1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 09:52:16 -05:00

Fixed startActivityForResult() failing for MessageList

Fixes issue 3638
This commit is contained in:
cketti 2011-11-06 23:37:49 +01:00
parent f677781bce
commit e2e9f8b6a3
3 changed files with 37 additions and 55 deletions

View File

@ -27,9 +27,6 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- In order to properly manage the BACK key, we do some check on the running tasks -->
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" /> <uses-permission android:name="org.thialfihar.android.apg.permission.READ_KEY_DETAILS" />
<permission android:name="com.fsck.k9.permission.READ_ATTACHMENT" <permission android:name="com.fsck.k9.permission.READ_ATTACHMENT"
@ -207,7 +204,7 @@
</activity> </activity>
<activity <activity
android:name="com.fsck.k9.activity.MessageList" android:name="com.fsck.k9.activity.MessageList"
android:launchMode="singleInstance" android:launchMode="singleTask"
android:configChanges="locale" android:configChanges="locale"
> >
</activity> </activity>

View File

@ -25,7 +25,6 @@ import android.util.TypedValue;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -554,6 +553,9 @@ public class MessageList
public static Intent actionHandleFolderIntent(Context context, Account account, String folder) { public static Intent actionHandleFolderIntent(Context context, Account account, String folder) {
Intent intent = new Intent(context, MessageList.class); Intent intent = new Intent(context, MessageList.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(EXTRA_ACCOUNT, account.getUuid()); intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
if (folder != null) { if (folder != null) {
@ -573,6 +575,9 @@ public class MessageList
} }
intent.putExtra(EXTRA_INTEGRATE, integrate); intent.putExtra(EXTRA_INTEGRATE, integrate);
intent.putExtra(EXTRA_TITLE, title); intent.putExtra(EXTRA_TITLE, title);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent); context.startActivity(intent);
} }
@ -589,6 +594,9 @@ public class MessageList
intent.putExtra(EXTRA_ACCOUNT_UUIDS, searchSpecification.getAccountUuids()); intent.putExtra(EXTRA_ACCOUNT_UUIDS, searchSpecification.getAccountUuids());
intent.putExtra(EXTRA_FOLDER_NAMES, searchSpecification.getFolderNames()); intent.putExtra(EXTRA_FOLDER_NAMES, searchSpecification.getFolderNames());
intent.putExtra(EXTRA_TITLE, title); intent.putExtra(EXTRA_TITLE, title);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent); context.startActivity(intent);
} }
@ -618,6 +626,12 @@ public class MessageList
mInflater = getLayoutInflater(); mInflater = getLayoutInflater();
initializeLayout(); initializeLayout();
// Only set "touchable" when we're first starting up the activity.
// Otherwise we get force closes when the user toggles it midstream.
mTouchView = K9.messageListTouchable();
mPreviewLines = K9.messageListPreviewLines();
onNewIntent(getIntent()); onNewIntent(getIntent());
} }
@ -625,22 +639,30 @@ public class MessageList
public void onNewIntent(Intent intent) { public void onNewIntent(Intent intent) {
setIntent(intent); // onNewIntent doesn't autoset our "internal" intent setIntent(intent); // onNewIntent doesn't autoset our "internal" intent
// Only set "touchable" when we're first starting up the activity.
// Otherwise we get force closes when the user toggles it midstream.
mTouchView = K9.messageListTouchable();
mPreviewLines = K9.messageListPreviewLines();
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT); String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid); Account account = Preferences.getPreferences(this).getAccount(accountUuid);
mFolderName = intent.getStringExtra(EXTRA_FOLDER); String folderName = intent.getStringExtra(EXTRA_FOLDER);
mQueryString = intent.getStringExtra(EXTRA_QUERY); String queryString = intent.getStringExtra(EXTRA_QUERY);
if (mAccount != null && !mAccount.isAvailable(this)) { if (account != null && !account.isAvailable(this)) {
Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account"); Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account");
onAccountUnavailable(); onAccountUnavailable();
return; return;
} }
if (account != null && account.equals(mAccount) &&
folderName != null && folderName.equals(mFolderName) &&
((queryString != null && queryString.equals(mQueryString)) ||
(queryString == null && mQueryString == null))) {
// We're likely just returning from the MessageView activity with "Manage back button"
// enabled. So just leave the activity in the state it was left in.
return;
}
mAccount = account;
mFolderName = folderName;
mQueryString = queryString;
String queryFlags = intent.getStringExtra(EXTRA_QUERY_FLAGS); String queryFlags = intent.getStringExtra(EXTRA_QUERY_FLAGS);
if (queryFlags != null) { if (queryFlags != null) {
String[] flagStrings = queryFlags.split(","); String[] flagStrings = queryFlags.split(",");
@ -1070,7 +1092,7 @@ public class MessageList
MessageReference ref = message.message.makeMessageReference(); MessageReference ref = message.message.makeMessageReference();
Log.i(K9.LOG_TAG, "MessageList sending message " + ref); Log.i(K9.LOG_TAG, "MessageList sending message " + ref);
MessageView.actionView(this, ref, messageRefs, getIntent()); MessageView.actionView(this, ref, messageRefs);
} }
/* /*

View File

@ -1,7 +1,5 @@
package com.fsck.k9.activity; package com.fsck.k9.activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
@ -36,7 +34,6 @@ import java.util.*;
public class MessageView extends K9Activity implements OnClickListener { public class MessageView extends K9Activity implements OnClickListener {
private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference"; private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference";
private static final String EXTRA_MESSAGE_REFERENCES = "com.fsck.k9.MessageView_messageReferences"; private static final String EXTRA_MESSAGE_REFERENCES = "com.fsck.k9.MessageView_messageReferences";
private static final String EXTRA_ORIGINATING_INTENT = "com.fsck.k9.MessageView_originatingIntent";
private static final String EXTRA_NEXT = "com.fsck.k9.MessageView_next"; private static final String EXTRA_NEXT = "com.fsck.k9.MessageView_next";
private static final String SHOW_PICTURES = "showPictures"; private static final String SHOW_PICTURES = "showPictures";
private static final String STATE_PGP_DATA = "pgpData"; private static final String STATE_PGP_DATA = "pgpData";
@ -65,12 +62,6 @@ public class MessageView extends K9Activity implements OnClickListener {
HAS_SUPER_ON_BACK_METHOD = hasOnBackMethod; HAS_SUPER_ON_BACK_METHOD = hasOnBackMethod;
} }
/**
* If user opt-in for the "Manage BACK button", we have to remember how to get back to the
* originating activity (just recreating a new Intent could lose the calling activity state)
*/
private Intent mCreatorIntent;
private SingleMessageView mMessageView; private SingleMessageView mMessageView;
private PgpData mPgpData; private PgpData mPgpData;
@ -275,20 +266,8 @@ public class MessageView extends K9Activity implements OnClickListener {
// or later, or by the code above on earlier versions of the // or later, or by the code above on earlier versions of the
// platform. // platform.
if (K9.manageBack()) { if (K9.manageBack()) {
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); String folder = (mMessage != null) ? mMessage.getFolder().getName() : null;
// retrieve the current+previous tasks MessageList.actionHandleFolder(this, mAccount, folder);
final List<RunningTaskInfo> 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(); finish();
} else if (HAS_SUPER_ON_BACK_METHOD) { } else if (HAS_SUPER_ON_BACK_METHOD) {
super.onBackPressed(); super.onBackPressed();
@ -348,29 +327,15 @@ public class MessageView extends K9Activity implements OnClickListener {
} }
/**
* @param context
* @param messRef
* @param messReferences
* @param originatingIntent
* The intent that allow us to get back to the calling screen, for when the 'Manage
* "Back" button' option is enabled. Never {@code null}.
*/
public static void actionView(Context context, MessageReference messRef, public static void actionView(Context context, MessageReference messRef,
ArrayList<MessageReference> messReferences, final Intent originatingIntent) { ArrayList<MessageReference> messReferences) {
Intent i = new Intent(context, MessageView.class); Intent i = new Intent(context, MessageView.class);
i.putExtra(EXTRA_MESSAGE_REFERENCE, messRef); i.putExtra(EXTRA_MESSAGE_REFERENCE, messRef);
i.putParcelableArrayListExtra(EXTRA_MESSAGE_REFERENCES, messReferences); i.putParcelableArrayListExtra(EXTRA_MESSAGE_REFERENCES, messReferences);
i.putExtra(EXTRA_ORIGINATING_INTENT, originatingIntent);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i); context.startActivity(i);
} }
@Override
protected void onNewIntent(final Intent intent) {
mCreatorIntent = intent.getParcelableExtra(EXTRA_ORIGINATING_INTENT);
}
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle, false); super.onCreate(icicle, false);
@ -412,8 +377,6 @@ public class MessageView extends K9Activity implements OnClickListener {
setTitle(""); setTitle("");
final Intent intent = getIntent(); final Intent intent = getIntent();
mCreatorIntent = getIntent().getParcelableExtra(EXTRA_ORIGINATING_INTENT);
Uri uri = intent.getData(); Uri uri = intent.getData();
if (icicle != null) { if (icicle != null) {
mMessageReference = icicle.getParcelable(EXTRA_MESSAGE_REFERENCE); mMessageReference = icicle.getParcelable(EXTRA_MESSAGE_REFERENCE);