From 06514f3a19b73356df0a2bc274749b8fbb59c84f Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 19 Jan 2012 11:16:07 -0800 Subject: [PATCH] Try/catch in update message dialog to fix crashes with trying to show with a non-running activity --- .../astrid/service/UpdateMessageService.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java b/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java index b3684b87b..cba067453 100644 --- a/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java +++ b/astrid/src/com/todoroo/astrid/service/UpdateMessageService.java @@ -14,6 +14,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.text.TextUtils; +import android.view.WindowManager.BadTokenException; import com.timsu.astrid.R; import com.todoroo.andlib.data.Property.StringProperty; @@ -91,8 +92,20 @@ public class UpdateMessageService { activity.runOnUiThread(new Runnable() { @Override public void run() { - DialogUtilities.htmlDialog(activity, - html, R.string.UpS_updates_title); + try { + DialogUtilities.htmlDialog(activity, + html, R.string.UpS_updates_title); + } catch (BadTokenException bt) { + try { + Activity current = (Activity) ContextManager.getContext(); + DialogUtilities.htmlDialog(current, + html, R.string.UpS_updates_title); + } catch (ClassCastException c) { + // Oh well, context wasn't an activity + } catch (BadTokenException bt2) { + // Oh well, activity isn't running + } + } } }); }