【问题标题】:Window Leaked During Orientation Change on AlertDialog在 AlertDialog 上更改方向期间窗口泄漏
【发布时间】:2013-09-12 03:01:23
【问题描述】:

在主活动内部实例化的另一个类包含显示警报对话框的此方法。在方向更改期间,我仍然让窗口泄漏。我还检查了几个问题,他们得到了相似的答案。

主类:

AlertDialog aler;
classB(aler);

B 类:

AlertDialog aler2;
classB(AlertDialog a){
this.aler2 = a;
}

private void showWifiDialog(AlertDialog aler2) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this.context)
            .setTitle("Device")
            .setMessage("Press OK")
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });

    aler2 = builder.create();

    aler2.show();

}

实验:

    @Override
    public void onPause() {
            if(aler!=null && aler.isShowing())
         {
             aler.cancel();
         }
      super.onPause();
    }

   @Override
    public void onStop(){
        if(aler!= null && aler.isShowing()) {

            aler.dismiss();

          }
        super.onStop();
    }

    @Override
    protected void onDestroy() {
     // TODO Auto-generated method stub

        if(aler!=null)
         {
             aler.dismiss();
         }
    }

【问题讨论】:

    标签: java android memory-leaks android-alertdialog android-dialog


    【解决方案1】:

    试试这个,把它放在清单中然后试试

    <activity
                android:name="ActivityWhcichCallingDialog"
                android:configChanges="keyboardHidden|orientation|screenSize"
    />
    

    【讨论】:

    • 尽量不使用configchanges先生。
    猜你喜欢
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    • 2011-08-07
    • 1970-01-01
    相关资源
    最近更新 更多