2015-09-22 31 views
1

我收到错误消息。活动com.act.hyd.app.EmtyActivity泄漏了最初在此处添加的窗口[email protected]

Activity com.act.hyd.app.EmtyActivity has leaked window [email protected] 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(); 
      } 
+0

的可能重复【活动已泄漏最初加入窗口(http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added ) –

+0

发布活动的源代码,我认为你可能会多次调用警报。 – MAOL

回答

0

就在您进入新的活动之前,您需要关闭当前活动的对话框。

.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); 

         } 
         }) 

否则对话框窗口会被泄漏。

好运

+1

Tnx ...它为我工作。 –

1

你需要调用

alertDialogBuilder.dismiss()

你完成Activty之前。

0

setNegativeButton功能你都呼吁dialog.dismiss();但是你有没有解雇你的对话框上setPositiveButton,所以你还需要解散你的对话框中setPositiveButton功能。

OR

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

public void onDestroy() { 
super.onDestroy(); 

    if(dialog !=null) 
    { 
    dialog.dismiss(); 
    } 
} 
相关问题