1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-23 16:18:50 -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.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" />
<permission android:name="com.fsck.k9.permission.READ_ATTACHMENT"
@ -207,7 +204,7 @@
</activity>
<activity
android:name="com.fsck.k9.activity.MessageList"
android:launchMode="singleInstance"
android:launchMode="singleTask"
android:configChanges="locale"
>
</activity>

View File

@ -25,7 +25,6 @@ import android.util.TypedValue;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
@ -554,6 +553,9 @@ public class MessageList
public static Intent actionHandleFolderIntent(Context context, Account account, String folder) {
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());
if (folder != null) {
@ -573,6 +575,9 @@ public class MessageList
}
intent.putExtra(EXTRA_INTEGRATE, integrate);
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);
}
@ -589,6 +594,9 @@ public class MessageList
intent.putExtra(EXTRA_ACCOUNT_UUIDS, searchSpecification.getAccountUuids());
intent.putExtra(EXTRA_FOLDER_NAMES, searchSpecification.getFolderNames());
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);
}
@ -618,6 +626,12 @@ public class MessageList
mInflater = getLayoutInflater();
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());
}
@ -625,22 +639,30 @@ public class MessageList
public void onNewIntent(Intent 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);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mFolderName = intent.getStringExtra(EXTRA_FOLDER);
mQueryString = intent.getStringExtra(EXTRA_QUERY);
Account account = Preferences.getPreferences(this).getAccount(accountUuid);
String folderName = intent.getStringExtra(EXTRA_FOLDER);
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");
onAccountUnavailable();
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);
if (queryFlags != null) {
String[] flagStrings = queryFlags.split(",");
@ -1070,7 +1092,7 @@ public class MessageList
MessageReference ref = message.message.makeMessageReference();
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;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
@ -36,7 +34,6 @@ import java.util.*;
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_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 SHOW_PICTURES = "showPictures";
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;
}
/**
* 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 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
// platform.
if (K9.manageBack()) {
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// retrieve the current+previous tasks
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);
}
String folder = (mMessage != null) ? mMessage.getFolder().getName() : null;
MessageList.actionHandleFolder(this, mAccount, folder);
finish();
} else if (HAS_SUPER_ON_BACK_METHOD) {
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,
ArrayList<MessageReference> messReferences, final Intent originatingIntent) {
ArrayList<MessageReference> messReferences) {
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);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
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);
@ -412,8 +377,6 @@ public class MessageView extends K9Activity implements OnClickListener {
setTitle("");
final Intent intent = getIntent();
mCreatorIntent = getIntent().getParcelableExtra(EXTRA_ORIGINATING_INTENT);
Uri uri = intent.getData();
if (icicle != null) {
mMessageReference = icicle.getParcelable(EXTRA_MESSAGE_REFERENCE);