diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index adcf82dca..42b93cc38 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -26,6 +26,10 @@
+
+
+
+
runningTasks = activityManager.getRunningTasks(2);
+ final RunningTaskInfo previousTask = runningTasks.get(1);
+ final String originatingActivity = mCreatorIntent.getComponent().getClassName();
+ if (originatingActivity.equals(previousTask.topActivity.getClassName())) {
+ // we can safely just finish ourself since the most recent task matches our creator
+ // this enable us not to worry about restoring the state of our creator
+ } else {
+ // the previous task top activity doesn't match our creator (previous task is from
+ // another app and user used long-pressed-HOME to display MessageView)
+ // launching our creator
+ startActivity(mCreatorIntent);
+ }
finish();
} else if (HAS_SUPER_ON_BACK_METHOD) {
super.onBackPressed();
@@ -328,20 +350,35 @@ public class MessageView extends K9Activity implements OnClickListener {
}
- public static void actionView(Context context, MessageReference messRef, ArrayList messReferences) {
- actionView(context, messRef, messReferences, null);
+ public static void actionView(Context context, MessageReference messRef, ArrayList messReferences, final Intent originatingIntent) {
+ actionView(context, messRef, messReferences, null, originatingIntent);
}
- public static void actionView(Context context, MessageReference messRef, ArrayList messReferences, Bundle extras) {
+ /**
+ * @param context
+ * @param messRef
+ * @param messReferences
+ * @param extras
+ * @param originatingIntent
+ * The intent that allow us to get back to the calling screen, for when the 'Manage
+ * BACK' option is enabled. Never {@code null}.
+ */
+ public static void actionView(Context context, MessageReference messRef, ArrayList messReferences, Bundle extras, final Intent originatingIntent) {
Intent i = new Intent(context, MessageView.class);
i.putExtra(EXTRA_MESSAGE_REFERENCE, messRef);
i.putParcelableArrayListExtra(EXTRA_MESSAGE_REFERENCES, messReferences);
+ i.putExtra(EXTRA_ORIGINATING_INTENT, originatingIntent);
if (extras != null) {
i.putExtras(extras);
}
context.startActivity(i);
}
+ @Override
+ protected void onNewIntent(final Intent intent) {
+ mCreatorIntent = intent.getParcelableExtra(EXTRA_ORIGINATING_INTENT);
+ }
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle, false);
@@ -381,7 +418,10 @@ public class MessageView extends K9Activity implements OnClickListener {
mMessageView.initialize(this);
setTitle("");
- Intent intent = getIntent();
+ final Intent intent = getIntent();
+
+ mCreatorIntent = getIntent().getParcelableExtra(EXTRA_ORIGINATING_INTENT);
+
Uri uri = intent.getData();
if (icicle != null) {
mMessageReference = icicle.getParcelable(EXTRA_MESSAGE_REFERENCE);