【问题标题】:Activity com.act.hyd.app.EmtyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@416e8bb8 that was originally added here活动 com.act.hyd.app.EmtyActivity 泄露了最初添加在这里的窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@416e8bb8
【发布时间】:2015-12-19 07:58:33
【问题描述】:

我遇到了错误。

Activity com.act.hyd.app.EmtyActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@416e8bb8 that was originally added here

在初始屏幕中,我将检查应用程序的版本代码。如果版本不合适,则显示AlertDialog。但是我得到了上述错误。如何解决它。

public void incorrectMessages(){


           AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);

                // set title
                alertDialogBuilder.setTitle("Your Title");

                // set dialog message
                alertDialogBuilder
                    .setMessage("Click yes to exit!")
                    .setCancelable(false)
                    .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, close
                            // current activity
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
                            startActivity(browserIntent);
                        }
                      })
                    .setNegativeButton("No",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, just close
                            // the dialog box and do nothing
                            dialog.dismiss();
                        }
                    });

                    // create alert dialog
                    AlertDialog alertDialog = alertDialogBuilder.create();

                    // show it
                    alertDialog.show();




                 Toast.makeText(getApplicationContext(), "Dear ACT Customer your App looks old version .Please upgrade from Playstore ", Toast.LENGTH_LONG).show();
                 onRestart();
             }

【问题讨论】:

标签: android


【解决方案1】:

就在你去新的Activity之前,你需要关闭当前Activity的对话框。

.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, close
                            // current activity
                            // --------------------------
                            // here you need to dismiss the dialog
                             dialog.dismiss();
                            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
                            startActivity(browserIntent);

                        }
                      })

否则对话窗口会被泄露。

祝你好运

【讨论】:

    【解决方案2】:

    setNegativeButton 函数你被称为 dialog.dismiss(); 但你还没有关闭 setPositiveButton 上的对话框,所以你还需要关闭 setPositiveButton 函数中的对话框。

    您也可以使用onDestroy()。在您的活动上写下功能

    public void onDestroy() {
    super.onDestroy();
    
      if(dialog !=null)
      {
        dialog.dismiss();
      }
    }
    

    【讨论】:

      【解决方案3】:

      你需要打电话

      alertDialogBuilder.dismiss()

      在您完成活动之前。

      【讨论】: