2014-12-29 62 views
0

我在SherlockFragment中的操作欄上使用菜單,onClick打開警告對話框,這工作正常,但如果我回去,而對話框不顯示,應用程序崩潰並登錄貓說窗滲漏,我試圖解僱的onPause和調用OnStop對話框但沒有工作我android:sherlock活動時警告對話框的窗口泄漏

AlertDialog.Builder builder = new AlertDialog.Builder(
      getSherlockActivity()); 
    builder.setTitle(messageTitle) 
      .setMessage(message) 
      .setCancelable(false) 
      .setNegativeButton("No", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        dialog.cancel(); 
       } 
      }) 
      .setPositiveButton("Yes", 
        new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          // TODO Auto-generated method stub 

         } 

        }); 
    AlertDialog alert = builder.create(); 
    alert.show(); 
+1

添加您的日誌也 – VicJordan

+1

更改下面的代碼alertDialog = builder.show(); 然後在onDestory()方法中調用alertDialog.dismiss(); –

+0

發佈完整代碼 –

回答

1

你得做這種方式 -
聲明Alertdialog alert = null;全球;

然後onPause()檢查alert!=null

alert.dismiss();

+0

這適用於2.3以上版本,但不適用於2.3vn以下版本? – Arslan

+0

我對此沒有想法,哪些支持庫用於在2.3v以下啓用sherlokFragment? – Darpan

+0

import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; – Arslan

相關問題