更改背景颜色没有效果,一旦屏幕被旋转 [英] Change background color has no effect once screen has been rotated

查看:188
本文介绍了更改背景颜色没有效果,一旦屏幕被旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有我是新来的Andr​​oid,现在我面临着一个奇怪的问题,总之,问题是

all I am new to Android and now I am facing a strange problem, the problem in short is

接收TCP消息,然后改变背景颜色的图形用户界面没有一次屏幕已被旋转的效果。

我要归档什么:

对Android设备上运行的应用程序,通过TCP连接到PC。 PC可以发送一个字符串,应用程序,应用程序会那么做一些基础的弦接收。 在这种情况下,一个字符串,底色变回红色(与手机振动)/黑是通过TCP发送到应用程序,因此Android用户将看到与振动眩目的效果。

Have a APP running on Android device, connect to a PC via TCP. PC can send a string to APP, the APP will then do something base on string received. In this case a string, "change back ground color to red(with phone vibrates)/black" is send to APP via TCP, so Android user will see a blinding effect with vibration.

什么问题:

我可以存档我想要的。但一旦在屏幕已被旋转,颜色不能被改变,只有振动仍

I can archive what I want. But once the screen has been rotated, the color cannot be changed, only vibration remain.

我曾尝试:

我穿上这将手工触发颜色变化时(振动)的应用程序中的按钮。它工作正常,即使我旋转屏幕。

I put a button on the APP which will manually trigger color change event(with vibration). It works fine even if I rotate the screen.

另外实验表明,UI操作,例如更改背景颜色和动画通过TCP读触发的消失,但是铃声和振动保持不变。

Further test shows that UI operation such as change background color and animation triggered by TCP read are vanished, however ringtone and vibration remain unchanged.

我将视频上传到YouTube http://youtu.be/n0gxXzzf-bo

I upload a video to Youtube http://youtu.be/n0gxXzzf-bo

下面是java的code,按钮和TCP调用同样的方法:ChangeColor()

Below are java code ,the button and TCP call same method: ChangeColor()

public void ChangeColor(){
    Thread t= new Thread(new ChangeColorTest());        
    t.start();
}
public class ChangeColorTest  implements Runnable{


    public void run() {             
            try {
                    for(int i=0;i<3;i++){

                    mBlinkHandler.sendEmptyMessageDelayed(1, 0);                    
                    Thread.sleep(300);              
                    mBlinkHandler.sendEmptyMessageDelayed(2, 0);
                    Thread.sleep(300);                  

                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }   


}


Handler mBlinkHandler = new Handler(){
        @Override
        public void handleMessage(Message msg){
             super.handleMessage(msg);
            //   mScreen = (LinearLayout)findViewById(R.id.mylinerlayout);
             if(msg.what==1){
             mScreen.setBackgroundColor(Color.RED);
             Vibratoration();
             }else if(msg.what==2){
             mScreen.setBackgroundColor(Color.BLACK);
             }
        }
    };

我想知道的是什么?

如果有人能可能找出解决的办法,这将是更AP preciated。

If someone could possible figure out a solution, it would be much appreciated.

什么是我的平台? 服务器PC:Win7的64位VS2010 C# Android平台:4.0三星S2 开发IDE:MOTODEV SDK API:安卓3

What is my platform? Server PC: Win7 64bits VS2010 C# Android platform: 4.0 Samsung S2 Development IDE:Motodev SDK API: Android 3

推荐答案

Android将当你旋转屏幕重建整个活动

Android will recreate the whole activity when you rotate the screen - so probably your variable "mScreen" won't point to the instance actually visible on the screen after rotation.

您可以避开,那Android的再现如下解释的活动: http://developer.android.com/guide/topics/resources/runtime -changes.html

You can avoid, that android recreates the activity as explained here: http://developer.android.com/guide/topics/resources/runtime-changes.html

这篇关于更改背景颜色没有效果,一旦屏幕被旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆