Skip to content

Commit 01df6a8

Browse files
committed
fix bug where the instance saving of the ChooseTypeAndAccountActivity
would only work in the case where onSaveInstanceState was called. - combined mExistingAccounts and mSavedAccounts into one field - set this field when starting the addAccount request - write this to the instance state if the request state is ADDING_ACCOUNT - read this field from the instance state, if any, when the request state is ADDING_ACCOUNT Bug: 5459669 Change-Id: I5a7b4943de8e706cc8a21ff9f54fce4258f18b19
1 parent 11116b8 commit 01df6a8

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

core/java/android/accounts/ChooseTypeAndAccountActivity.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class ChooseTypeAndAccountActivity extends Activity
7272
* This is passed as the requiredFeatures parameter in AccountManager.addAccount()
7373
* if it is called.
7474
*/
75-
public static final String EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY =
75+
public static final String EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY =
7676
"addAccountRequiredFeatures";
7777

7878
/**
@@ -110,7 +110,6 @@ public class ChooseTypeAndAccountActivity extends Activity
110110
private ArrayList<AccountInfo> mAccountInfos;
111111
private int mPendingRequest = REQUEST_NULL;
112112
private Parcelable[] mExistingAccounts = null;
113-
private Parcelable[] mSavedAccounts = null;
114113

115114
@Override
116115
public void onCreate(Bundle savedInstanceState) {
@@ -124,12 +123,10 @@ public void onCreate(Bundle savedInstanceState) {
124123

125124
if (savedInstanceState != null) {
126125
mPendingRequest = savedInstanceState.getInt(KEY_INSTANCE_STATE_PENDING_REQUEST);
127-
mSavedAccounts =
126+
mExistingAccounts =
128127
savedInstanceState.getParcelableArray(KEY_INSTANCE_STATE_EXISTING_ACCOUNTS);
129-
mExistingAccounts = null;
130128
} else {
131129
mPendingRequest = REQUEST_NULL;
132-
mSavedAccounts = null;
133130
mExistingAccounts = null;
134131
}
135132

@@ -246,7 +243,9 @@ protected void onDestroy() {
246243
protected void onSaveInstanceState(final Bundle outState) {
247244
super.onSaveInstanceState(outState);
248245
outState.putInt(KEY_INSTANCE_STATE_PENDING_REQUEST, mPendingRequest);
249-
outState.putParcelableArray(KEY_INSTANCE_STATE_EXISTING_ACCOUNTS, mExistingAccounts);
246+
if (mPendingRequest == REQUEST_ADD_ACCOUNT) {
247+
outState.putParcelableArray(KEY_INSTANCE_STATE_EXISTING_ACCOUNTS, mExistingAccounts);
248+
}
250249
}
251250

252251
// Called when the choose account type activity (for adding an account) returns.
@@ -264,7 +263,6 @@ protected void onActivityResult(final int requestCode, final int resultCode,
264263

265264
// we got our result, so clear the fact that we had a pending request
266265
mPendingRequest = REQUEST_NULL;
267-
mExistingAccounts = null;
268266

269267
if (resultCode == RESULT_CANCELED) {
270268
return;
@@ -293,7 +291,7 @@ protected void onActivityResult(final int requestCode, final int resultCode,
293291
if (accountName == null || accountType == null) {
294292
Account[] currentAccounts = AccountManager.get(this).getAccounts();
295293
Set<Account> preExistingAccounts = new HashSet<Account>();
296-
for (Parcelable accountParcel : mSavedAccounts) {
294+
for (Parcelable accountParcel : mExistingAccounts) {
297295
preExistingAccounts.add((Account) accountParcel);
298296
}
299297
for (Account account : currentAccounts) {

0 commit comments

Comments
 (0)