From e00a31155b95686eecc6e1999e904472f8f300ca Mon Sep 17 00:00:00 2001 From: Fred Quintana Date: Tue, 22 Sep 2009 15:13:30 -0700 Subject: [PATCH] - make an AccountManager per context, not one per process - enhance the comment for addOnAccountsUpdatedListener() --- core/java/android/accounts/AccountManager.java | 4 ++++ core/java/android/app/ApplicationContext.java | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java index 9afeb74b02f4c..1ee7f60fb9ce8 100644 --- a/core/java/android/accounts/AccountManager.java +++ b/core/java/android/accounts/AccountManager.java @@ -807,6 +807,10 @@ public class AccountManager { * Add a {@link OnAccountsUpdatedListener} to this instance of the {@link AccountManager}. * The listener is guaranteed to be invoked on the thread of the Handler that is passed * in or the main thread's Handler if handler is null. + *

+ * You must remove this listener before the context that was used to retrieve this + * {@link AccountManager} instance goes away. This generally means when the Activity + * or Service you are running is stopped. * @param listener the listener to add * @param handler the Handler whose thread will be used to invoke the listener. If null * the AccountManager context's main thread will be used. diff --git a/core/java/android/app/ApplicationContext.java b/core/java/android/app/ApplicationContext.java index afafe64c5602d..8896015cd7814 100644 --- a/core/java/android/app/ApplicationContext.java +++ b/core/java/android/app/ApplicationContext.java @@ -153,7 +153,6 @@ class ApplicationContext extends Context { private final static boolean DEBUG_ICONS = false; private static final Object sSync = new Object(); - private static AccountManager sAccountManager; private static AlarmManager sAlarmManager; private static PowerManager sPowerManager; private static ConnectivityManager sConnectivityManager; @@ -186,6 +185,7 @@ class ApplicationContext extends Context { private boolean mIsBluetoothAdapterCached = false; private BluetoothAdapter mBluetoothAdapter; private boolean mRestricted; + private AccountManager mAccountManager; // protected by mSync private final Object mSync = new Object(); @@ -908,14 +908,14 @@ class ApplicationContext extends Context { } private AccountManager getAccountManager() { - synchronized (sSync) { - if (sAccountManager == null) { + synchronized (mSync) { + if (mAccountManager == null) { IBinder b = ServiceManager.getService(ACCOUNT_SERVICE); IAccountManager service = IAccountManager.Stub.asInterface(b); - sAccountManager = new AccountManager(this, service); + mAccountManager = new AccountManager(this, service); } + return mAccountManager; } - return sAccountManager; } private ActivityManager getActivityManager() {