I try to add AlertDialog to do rename such as below code:
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);
}
});
But the error occurs.
Activity AActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2b0278a8 that was originally added here
It was cause by new Intent start and pause the old one.
But how to avoid it?
Launch the intent after you clicked a button on the dialog like this:
I’ve put it in both buttons, but probably you only want it when the user clicks ok so it should only be placed there. YOu can do it without the function then.