我想添加 AlertDialog 來重新命名,下面的代碼:
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) {
}
});
renameDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
renameDialog.show();
}
}
Intent it = new Intent(AActivity.this, BActivity.class);
it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(it);
}
});
但是發生錯誤:
Activity AActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2b0278a8 that was originally added here
這是由於新的 intent 開啟,舊的 intent 暫停造成的,如何避免這個問題呢?
在Activity的Destory得銷毀Dialog 例如:
public void onDestory() {
if(dialog!= null) {
dialog.dismiss();
dialog = null;
}
}
不然就會出現你這個錯誤了
還有你這個跳轉,不是在Dialog的onCLick做處理嗎? 應該是獲取Dialog中的原密碼 新密碼什麼的判斷後跳轉的吧
Intent it = new Intent(AActivity.this, BActivity.class);
it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(it);