Android: Can not change the text appears in AlertDialog
I think I have a fix for the inconsistent behavior of onPrepareDialog. When initially creating the dialog (when it's still an AlertDialog.Builder), you have to set the message to an initial state (not null) or onPrepareDialog will NOT overwrite the message with the intended value. So when you're creating the dialog, do something like this to always have a non-null value in the message. I struggled with this for days and found this solution by accident:
AlertDialog.Builder resultAlert = new AlertDialog.Builder(context);
if ( message == null ) {
resultAlert.setMessage("");
} else {
resultAlert.setMessage(message);
}
onPrepareDialog method is called when the dialog is shown. So, it is better to change the text or other features by overriding this method.