2012-01-05 31 views
1

我想在沒有網絡時退出我的應用程序 在退出之前,我想向用戶顯示消息 可以使用哪種對話。android:在退出應用程序時的對話

我試圖顯示來自的OnDestroy()

ALERT對話,但它給人的窗口泄漏例外

中的AsyncTask這裏我呼籲結束被檢測到網絡錯誤,所以我沒有看到任何其他地方加入對話。

所以我的問題是要添加哪個對話以及在哪裏添加。

protected void onDestroy() { 
    super.onDestroy(); 
    showExitDialogue(); 
    Log.i("StartUpActivity", "OnDestroy"); 
    if (asyncTaskForSync != null && !asyncTaskForSync.isCancelled()) 
     asyncTaskForSync.cancel(true); 
    if (mydb != null) 
     mydb.close(); 
    if (Utils.imageLoader != null) 
     Utils.imageLoader.stopThread(); 

} 
private static void showExitDialogue() { 
    AlertDialog.Builder alert = new AlertDialog.Builder(
      Utils.getStartActivityinstance()); 
    alert.setMessage("No internet connection"); 
    alert.setPositiveButton("Exit", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, 
         int whichButton) { 
        return; 
       } 
      });  
    alert.show(); 
} 

回答

1

,如果你檢查的AsyncTask網絡錯誤,則對話框應該把在onPostExecute(空隙V)

+0

謝謝你,你是對的。我不得不改變邏輯也有點叫主活動的結束從postExecute功能私有靜態無效showExitDialogue(){ \t \t AlertDialog.Builder警報=新AlertDialog.Builder( \t \t \t \t Utils.getStartActivityinstance()) ; \t \t alert.setMessage(「沒有互聯網連接」); \t \t alert.setPositiveButton( 「退出」,新DialogInterface.OnClickListener(){ \t \t \t公共無效的onClick(DialogInterface對話,詮釋whichButton){ \t \t \t \t Utils.getStartActivityinstance()結束(); \t \t \t} \t \t}); \t \t alert.show(); \t} – png 2012-01-05 03:04:45