- make an AccountManager per context, not one per process
- enhance the comment for addOnAccountsUpdatedListener()
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user