summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/accounts/AccountManager.java4
-rw-r--r--core/java/android/app/ApplicationContext.java10
2 files changed, 9 insertions, 5 deletions
diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java
index 9afeb74b02f4..1ee7f60fb9ce 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.
+ * <p>
+ * 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 afafe64c5602..8896015cd781 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() {