2012-01-05 7 views
1

ネットワークがないときにアプリケーションを終了します 終了する前に私はユーザーにメッセージを表示します どのダイアログがこれに使用できるのですか? アンドロイド:アプリケーションを終了している間にダイアログを開きます

iは、ネットワークエラーが、私は仕上げを呼び出すasynctaskで検出された

ALERT OnDestroy()

からDIALOGUEしかし、その与えるウィンドウリーク例外を表示しようとしたので、私は対話を追加するための他の場所を参照してくださいいけません。

私の質問は、追加するダイアログと追加する場所です。

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

あなたは正しいです、ありがとうございます。私はプライベートの静的な無効showExitDialogue(){ \t \t AlertDialog.Builder警告=新しいAlertDialog.Builder( \t \t \t \t Utils.getStartActivityinstance())postExecute機能から主な活動の仕上げを呼び出すためにもビットをロジックを変更する必要がありました; \t \t alert.setMessage( "No internet connection"); \t \t alert.setPositiveButton( "終了"、新DialogInterface.OnClickListener(){ \t \t \tます。public void onClickの(DialogInterfaceダイアログ、{ \t \t \t \t Utils.getStartActivityinstance())whichButtonをint型の仕上げ();。 \t \t \t} \t \t}); alert35.jpg \t} – png

関連する問題