From 8197d847343c6c20e6a98b2354bde5392b1c4542 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Mon, 8 Nov 2010 14:24:32 -0800 Subject: [PATCH] Don't call dismiss() in onLoadFinished(). It's prohibited. Instead use a Handler to delay-call it. Bug 3173317 Change-Id: Ic5ef245a65b3a4eeebabcebd6323b9a7921f34d5 --- .../email/activity/MoveMessageToDialog.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/com/android/email/activity/MoveMessageToDialog.java b/src/com/android/email/activity/MoveMessageToDialog.java index 2974b286b..3cc73112f 100644 --- a/src/com/android/email/activity/MoveMessageToDialog.java +++ b/src/com/android/email/activity/MoveMessageToDialog.java @@ -34,6 +34,7 @@ import android.content.DialogInterface; import android.content.Loader; import android.database.Cursor; import android.os.Bundle; +import android.os.Handler; import java.security.InvalidParameterException; @@ -141,6 +142,21 @@ public class MoveMessageToDialog extends DialogFragment implements DialogInterfa return (Callback) getActivity(); } + /** + * Delay-call {@link #dismiss()} using a {@link Handler}. Calling {@link #dismiss()} from + * {@link LoaderManager.LoaderCallbacks#onLoadFinished} is not allowed, so we use it instead. + */ + private void dismissAsync() { + new Handler().post(new Runnable() { + @Override + public void run() { + if (!mDestroyed) { + dismiss(); + } + } + }); + } + /** * Loader callback for {@link MessageChecker} */ @@ -157,7 +173,8 @@ public class MoveMessageToDialog extends DialogFragment implements DialogInterfa } // accountId shouldn't be null, but I'm paranoia. if ((accountId == null) || (accountId == -1)) { - dismiss(); // Some of the messages can't be moved. + // Some of the messages can't be moved. Close the dialog. + dismissAsync(); return; } mAccountId = accountId;