Bug 728263 - Avoid AccountManager leak error on exit. r=mfinkle

This commit is contained in:
Geoff Brown 2012-03-08 18:48:44 -05:00
parent 4d57056b4d
commit bff0e17716
2 changed files with 13 additions and 1 deletions

View File

@ -112,6 +112,7 @@ public class AboutHomeContent extends ScrollView {
private LayoutInflater mInflater;
private AccountManager mAccountManager;
private OnAccountsUpdateListener mAccountListener = null;
protected SimpleCursorAdapter mTopSitesAdapter;
protected GridView mTopSitesGrid;
@ -139,7 +140,7 @@ public class AboutHomeContent extends ScrollView {
mAccountManager = AccountManager.get(context);
// The listener will run on the background thread (see 2nd argument)
mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() {
mAccountManager.addOnAccountsUpdatedListener(mAccountListener = new OnAccountsUpdateListener() {
public void onAccountsUpdated(Account[] accounts) {
final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode();
final boolean syncIsSetup = isSyncSetup();
@ -210,6 +211,13 @@ public class AboutHomeContent extends ScrollView {
});
}
public void onDestroy() {
if (mAccountListener != null) {
mAccountManager.removeOnAccountsUpdatedListener(mAccountListener);
mAccountListener = null;
}
}
void setLastTabsVisibility(boolean visible) {
int visibility = visible ? View.VISIBLE : View.GONE;
findViewById(R.id.last_tabs_title).setVisibility(visibility);

View File

@ -2190,6 +2190,10 @@ abstract public class GeckoApp
super.onDestroy();
unregisterReceiver(mBatteryReceiver);
if (mAboutHomeContent != null) {
mAboutHomeContent.onDestroy();
}
}
@Override