diff --git a/src/com/android/email/RefreshManager.java b/src/com/android/email/RefreshManager.java index 67b732b7e..4e5fd5876 100644 --- a/src/com/android/email/RefreshManager.java +++ b/src/com/android/email/RefreshManager.java @@ -21,6 +21,7 @@ import com.android.emailcommon.mail.MessagingException; import com.android.emailcommon.utility.Utility; import android.content.Context; +import android.os.AsyncTask; import android.os.Handler; import android.util.Log; @@ -283,7 +284,8 @@ public class RefreshManager { if (LOG_ENABLED) { Log.d(Logging.LOG_TAG, "sendPendingMessagesForAllAccounts"); } - new SendPendingMessagesForAllAccountsImpl().execute(); + new SendPendingMessagesForAllAccountsImpl() + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } private class SendPendingMessagesForAllAccountsImpl extends Utility.ForEachAccount { diff --git a/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java b/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java index 31a20a011..2191a07dd 100644 --- a/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountCheckSettingsFragment.java @@ -158,7 +158,7 @@ public class AccountCheckSettingsFragment extends Fragment { Account checkAccount = SetupData.getAccount(); mAccountCheckTask = (AccountCheckTask) new AccountCheckTask(checkMode, checkAccount) - .execute(); + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } diff --git a/src/com/android/email/activity/setup/AccountSecurity.java b/src/com/android/email/activity/setup/AccountSecurity.java index 7692d9c2d..0f5a9ba23 100644 --- a/src/com/android/email/activity/setup/AccountSecurity.java +++ b/src/com/android/email/activity/setup/AccountSecurity.java @@ -160,7 +160,7 @@ public class AccountSecurity extends Activity { } finish(); } - }.execute(); + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } /** diff --git a/src/com/android/email/activity/setup/AccountServerBaseFragment.java b/src/com/android/email/activity/setup/AccountServerBaseFragment.java index 3da71cfd7..7f229c785 100644 --- a/src/com/android/email/activity/setup/AccountServerBaseFragment.java +++ b/src/com/android/email/activity/setup/AccountServerBaseFragment.java @@ -218,7 +218,8 @@ public abstract class AccountServerBaseFragment extends Fragment */ protected void startDuplicateTaskCheck(long accountId, String checkHost, String checkLogin, int checkSettingsMode) { - new DuplicateCheckTask(accountId, checkHost, checkLogin, checkSettingsMode).execute(); + new DuplicateCheckTask(accountId, checkHost, checkLogin, checkSettingsMode) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } /** @@ -329,7 +330,7 @@ public abstract class AccountServerBaseFragment extends Fragment // Signal to owning activity that a settings check completed mCallback.onCheckSettingsComplete(settingsResult, SetupData.getFlowMode()); } - }.execute(); + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } /** diff --git a/src/com/android/email/activity/setup/AccountSettings.java b/src/com/android/email/activity/setup/AccountSettings.java index ea1bb7689..03151528f 100644 --- a/src/com/android/email/activity/setup/AccountSettings.java +++ b/src/com/android/email/activity/setup/AccountSettings.java @@ -166,7 +166,8 @@ public class AccountSettings extends PreferenceActivity { if (ACTION_ACCOUNT_MANAGER_ENTRY.equals(i.getAction())) { // This case occurs if we're changing account settings from Settings -> Accounts mGetAccountIdFromAccountTask = - (GetAccountIdFromAccountTask) new GetAccountIdFromAccountTask().execute(i); + (GetAccountIdFromAccountTask) new GetAccountIdFromAccountTask() + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, i); } else { // Otherwise, we're called from within the Email app and look for our extras mRequestedAccountId = IntentUtilities.getAccountIdFromIntent(i); @@ -348,7 +349,8 @@ public class AccountSettings extends PreferenceActivity { if (hasHeaders()) { Utility.cancelTaskInterrupt(mLoadAccountListTask); mLoadAccountListTask = (LoadAccountListTask) - new LoadAccountListTask().execute(mDeletingAccountId); + new LoadAccountListTask().executeOnExecutor( + AsyncTask.THREAD_POOL_EXECUTOR, mDeletingAccountId); } } diff --git a/src/com/android/email/activity/setup/AccountSettingsFragment.java b/src/com/android/email/activity/setup/AccountSettingsFragment.java index a481232ee..8582bf39b 100644 --- a/src/com/android/email/activity/setup/AccountSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountSettingsFragment.java @@ -308,7 +308,8 @@ public class AccountSettingsFragment extends PreferenceFragment { */ public void startLoadingAccount(long accountId) { Utility.cancelTaskInterrupt(mLoadAccountTask); - mLoadAccountTask = new LoadAccountTask().execute(accountId); + mLoadAccountTask = new LoadAccountTask().executeOnExecutor( + AsyncTask.THREAD_POOL_EXECUTOR, accountId); } /** diff --git a/src/com/android/email/activity/setup/AccountSetupBasics.java b/src/com/android/email/activity/setup/AccountSetupBasics.java index b39cd9f25..0d4c2a7b6 100644 --- a/src/com/android/email/activity/setup/AccountSetupBasics.java +++ b/src/com/android/email/activity/setup/AccountSetupBasics.java @@ -208,7 +208,7 @@ public class AccountSetupBasics extends AccountSetupActivity // If there are one or more accounts already in existence, then display // the "use as default" checkbox (it defaults to hidden). - new DisplayCheckboxTask().execute(); + new DisplayCheckboxTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); boolean manualButtonDisplayed = true; boolean alternateStrings = false; @@ -436,7 +436,8 @@ public class AccountSetupBasics extends AccountSetupActivity // Stop here if the login credentials duplicate an existing account // Launch an Async task to do the work - new DuplicateCheckTask(this, recvAuth.mAddress, mProvider.incomingUsername).execute(); + new DuplicateCheckTask(this, recvAuth.mAddress, mProvider.incomingUsername) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (URISyntaxException e) { /* * If there is some problem with the URI we give up and go on to manual setup. diff --git a/src/com/android/email/activity/setup/AccountSetupNames.java b/src/com/android/email/activity/setup/AccountSetupNames.java index 0c69231a4..029ba2c76 100644 --- a/src/com/android/email/activity/setup/AccountSetupNames.java +++ b/src/com/android/email/activity/setup/AccountSetupNames.java @@ -50,7 +50,6 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi private EditText mName; private View mAccountNameLabel; private Button mNextButton; - private boolean mNextPressed = false; private boolean mEasAccount = false; public static void actionSetNames(Activity fromActivity) { @@ -122,13 +121,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi public void onClick(View v) { switch (v.getId()) { case R.id.next: - // Don't allow this more than once (we do some work in an async thread before - // finish()'ing the Activity, which allows this code to potentially be - // executed multiple times. - if (!mNextPressed) { - onNext(); - } - mNextPressed = true; + onNext(); break; } } @@ -154,7 +147,7 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi */ @Override public void onBackPressed() { - if (!mNextPressed) { + if (mNextButton.isEnabled()) { finishActivity(); } } @@ -180,6 +173,8 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi * and other steps to finish the creation of the account. */ private void onNext() { + mNextButton.setEnabled(false); // Protect against double-tap. + // Update account object from UI Account account = SetupData.getAccount(); String description = mDescription.getText().toString().trim(); @@ -189,7 +184,9 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi account.setSenderName(mName.getText().toString().trim()); // Launch async task for final commit work - new FinalSetupTask(account).execute(); + // Sicne it's a write task, use the serial executor so even if we ran the task twice + // with different values the result would be consistent. + new FinalSetupTask(account).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); } /**