Merge "[do not auto-merge] Check that Activity is still active after AsyncTask." into gingerbread
diff --git a/src/com/android/contacts/ui/EditContactActivity.java b/src/com/android/contacts/ui/EditContactActivity.java
index c70cff6..f1be8fb 100644
--- a/src/com/android/contacts/ui/EditContactActivity.java
+++ b/src/com/android/contacts/ui/EditContactActivity.java
@@ -144,6 +144,7 @@
private static final int STATUS_SAVING = 2;
private int mStatus;
+ private boolean mActivityActive; // true after onCreate/onResume, false at onPause
EntitySet mState;
@@ -172,6 +173,8 @@
// Handle initial actions only when existing state missing
final boolean hasIncomingState = icicle != null && icicle.containsKey(KEY_EDIT_STATE);
+ mActivityActive = true;
+
if (Intent.ACTION_EDIT.equals(action) && !hasIncomingState) {
setTitle(R.string.editContact_title_edit);
mStatus = STATUS_LOADING;
@@ -191,6 +194,18 @@
}
}
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mActivityActive = true;
+ }
+
+ @Override
+ protected void onPause() {
+ super.onResume();
+ mActivityActive = false;
+ }
+
private static class QueryEntitiesTask extends
WeakAsyncTask<Intent, Void, EntitySet, EditContactActivity> {
@@ -1211,6 +1226,10 @@
@Override
protected void onPostExecute(final EditContactActivity target, ArrayList<Account> accounts) {
+ if (!target.mActivityActive) {
+ // A monkey or very fast user.
+ return;
+ }
target.selectAccountAndCreateContact(accounts);
}
}