0

出现问题的视图里面有一个按钮和一个tabhost。该按钮的 onclick 侦听器会更改当前选项卡中的一些文本。问题是当我更改方向(端口到着陆或着陆到端口)时,按钮的 onclicklistener 会以某种方式被调用/浏览,并且当前选项卡中的文本会发生变化。为什么会发生这种情况,解决方案是什么?

myActivity extends Activity{
    onCreate(bundle){
        ..
        ..
        add(button1);
        button1.onClickListner(new OnClickListener(){
             ..
             someAlertDialog.show();             //line xxx

        });
    }

}

它实际上没有显示任何警报对话框(它不应该这样做)但说错误日志中有泄漏@line xxx。整个日志即将推出。

编辑:我现在无法获取错误日志,但是方向更改后仍然发生一些奇怪的事情。

4

1 回答 1

0

What happens by default on an orientation change is that the current activity instance is destroyed and then recreated and passed the previous instance's state. If a dialog is on screen when this happens it will leak the window that's displaying it.

Since you are not using Activity#showDialog which will manage dialogs when onDestroy is called you have to do that manually. So you'll have to override Activity#onDestroy and call Dialog#dismiss if it is showing.

于 2012-04-10T15:21:04.010 回答