2012-01-05 5 views
2

後、私はそのようなコード以下のように名前の変更を行うにAlertDialogを追加しよう。コール新しい意図はAlertDialog

Activity AActivity has leaked window [email protected] that was originally added here 

新しいインテントが古いものを開始して一時停止する原因でした。 しかし、それを避けるには?

+2

前にこのラインrenameDialog.dismiss();に追加]をクリックしAlertDialogボタン内の次のアクティビティを呼び出すためのテントを置きます。 –

+0

http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added –

答えて

6

起動...あなたは、このようなダイアログのボタンをクリックした後に意図ダイアログを閉じてください。

Button b = (Button)findViewById(R.id.btn); 
b.setOnClickListener(new OnClickListener() { 

@Override 
public void onClick(View v) { 
    AlertDialog.Builder renameDialog = new AlertDialog.Builder(AActivity.this); 
    renameDialog.setTitle("Rename"); 
    final EditText newName = new EditText(AActivity.this); 
    newName.setText(FilePath[i]); 
    renameDialog.setView(newName); 

    renameDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { 

     public void onClick(DialogInterface arg0, int arg1) { 
      launchIntent(); 
     } 
    }); 

    renameDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 

     public void onClick(DialogInterface arg0, int arg1) { 
      launchIntent(); 
     } 
    }); 

    renameDialog.show(); 
    } 

    private void launchIntent() { 
     Intent it = new Intent(AActivity.this, BActivity.class); 
     it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     startActivity(it); 
    } 
}); 

私は両方のボタンでそれを入れているのが、ユーザーが[OK]をクリックしたときだけ必要なので、その場所にのみ配置してください。あなたは機能なしでそれを行うことができます。

3

あなたの活動が終了する場合

1

あなたはonClick()のインテントを肯定的に設定する必要があります。

ない場合は、

あなたIntent

1
renameDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { 

       public void onClick(DialogInterface arg0, int arg1) { 
        Intent it = new Intent(AActivity.this, BActivity.class); 
        it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        startActivity(it); 
       } 
      }); 

      renameDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 

       public void onClick(DialogInterface arg0, int arg1) { 
       //arg0 should change to other word like "dialog" (i think it more make sense) 
       arg0.cancle(); 
       } 
      }); 

      renameDialog.show(); 
     }