diff options
author | Lifu Tang <lifu@google.com> | 2014-07-16 12:17:06 -0700 |
---|---|---|
committer | Lifu Tang <lifu@google.com> | 2014-07-16 23:12:03 +0000 |
commit | 42fa97345717d1a2421b173877284a0d6eca55e4 (patch) | |
tree | 7be3158cb574ff0c7c61a9fc8bbf0e64218a01a6 /src/com/android/settings/location | |
parent | b64a1f2fde227153510bd9147c05fb31bddd5a14 (diff) | |
download | packages_apps_Settings-42fa97345717d1a2421b173877284a0d6eca55e4.zip packages_apps_Settings-42fa97345717d1a2421b173877284a0d6eca55e4.tar.gz packages_apps_Settings-42fa97345717d1a2421b173877284a0d6eca55e4.tar.bz2 |
Avoid removing switch even listener multiple times
- Fix b/16118646
Change-Id: I36cdc5c8d98dfb63924737af40efff35b9ca2e66
Diffstat (limited to 'src/com/android/settings/location')
-rw-r--r-- | src/com/android/settings/location/LocationSettings.java | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/com/android/settings/location/LocationSettings.java b/src/com/android/settings/location/LocationSettings.java index 474a857..c0a13c1 100644 --- a/src/com/android/settings/location/LocationSettings.java +++ b/src/com/android/settings/location/LocationSettings.java @@ -54,17 +54,13 @@ public class LocationSettings extends LocationSettingsBase private SwitchBar mSwitchBar; private Switch mSwitch; - private boolean mValidListener; + private boolean mValidListener = false; private Preference mLocationMode; private PreferenceCategory mCategoryRecentLocationRequests; /** Receives UPDATE_INTENT */ private BroadcastReceiver mReceiver; private SettingsInjector injector; - public LocationSettings() { - mValidListener = false; - } - @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -79,21 +75,17 @@ public class LocationSettings extends LocationSettingsBase @Override public void onDestroyView() { super.onDestroyView(); - mSwitchBar.hide(); } @Override - public void onStop() { - super.onStop(); - } - - @Override public void onResume() { super.onResume(); createPreferenceHierarchy(); - mSwitchBar.addOnSwitchChangeListener(this); - mValidListener = true; + if (!mValidListener) { + mSwitchBar.addOnSwitchChangeListener(this); + mValidListener = true; + } } @Override @@ -102,10 +94,15 @@ public class LocationSettings extends LocationSettingsBase getActivity().unregisterReceiver(mReceiver); } catch (RuntimeException e) { // Ignore exceptions caused by race condition + if (Log.isLoggable(TAG, Log.VERBOSE)) { + Log.v(TAG, "Swallowing " + e); + } + } + if (mValidListener) { + mSwitchBar.removeOnSwitchChangeListener(this); + mValidListener = false; } super.onPause(); - mSwitchBar.removeOnSwitchChangeListener(this); - mValidListener = false; } private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) { |