1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

Don't attempt to configure a dismissed dialog during Android activity

reloading

As part of automatic activity reloading following a configuration
change, Android invokes Activity#onPrepareDialog() even for dismissed
dialogs. Consequently, one can't make the assumption that this method
is only invoked by explicit calls to Activity#showDialog() from our
code.

The actual problem here was the mActiveMessages member being null
at such times.
This commit is contained in:
Fiouz 2011-06-07 01:15:04 +02:00
parent 153c665084
commit fc4dd077e4

View File

@ -1293,6 +1293,14 @@ public class MessageList
return super.onCreateDialog(id); return super.onCreateDialog(id);
} }
/*
* (non-Javadoc)
*
* Android happens to invoke this method even if the given dialog is not
* shown (eg. a dismissed dialog) as part of the automatic activity
* reloading following a configuration change (orientation, keyboard,
* locale, etc.).
*/
@Override @Override
public void onPrepareDialog(final int id, final Dialog dialog) { public void onPrepareDialog(final int id, final Dialog dialog) {
switch (id) { switch (id) {
@ -1304,10 +1312,16 @@ public class MessageList
break; break;
} }
case R.id.dialog_confirm_spam: { case R.id.dialog_confirm_spam: {
final int selectionSize = mActiveMessages.size(); // mActiveMessages can be null if Android restarts the activity
final String message; // while this dialog is not actually shown (but was displayed at
message = getResources().getQuantityString(R.plurals.dialog_confirm_spam_message, selectionSize, Integer.valueOf(selectionSize)); // least once)
((AlertDialog) dialog).setMessage(message); if (mActiveMessages != null) {
final int selectionSize = mActiveMessages.size();
final String message;
message = getResources().getQuantityString(R.plurals.dialog_confirm_spam_message, selectionSize,
Integer.valueOf(selectionSize));
((AlertDialog) dialog).setMessage(message);
}
break; break;
} }
default: { default: {