am 569abb0c: Merge "Avoid removing switch even listener multiple times" into lmp-dev

* commit '569abb0c25708d4e7fc2cb4b3fe08839e253e211':
  Avoid removing switch even listener multiple times
This commit is contained in:
Lifu Tang
2014-07-17 18:16:28 +00:00
committed by Android Git Automerger

View File

@@ -54,17 +54,13 @@ public class LocationSettings extends LocationSettingsBase
private SwitchBar mSwitchBar; private SwitchBar mSwitchBar;
private Switch mSwitch; private Switch mSwitch;
private boolean mValidListener; private boolean mValidListener = false;
private Preference mLocationMode; private Preference mLocationMode;
private PreferenceCategory mCategoryRecentLocationRequests; private PreferenceCategory mCategoryRecentLocationRequests;
/** Receives UPDATE_INTENT */ /** Receives UPDATE_INTENT */
private BroadcastReceiver mReceiver; private BroadcastReceiver mReceiver;
private SettingsInjector injector; private SettingsInjector injector;
public LocationSettings() {
mValidListener = false;
}
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
@@ -79,22 +75,18 @@ public class LocationSettings extends LocationSettingsBase
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
mSwitchBar.hide(); mSwitchBar.hide();
} }
@Override
public void onStop() {
super.onStop();
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
createPreferenceHierarchy(); createPreferenceHierarchy();
if (!mValidListener) {
mSwitchBar.addOnSwitchChangeListener(this); mSwitchBar.addOnSwitchChangeListener(this);
mValidListener = true; mValidListener = true;
} }
}
@Override @Override
public void onPause() { public void onPause() {
@@ -102,11 +94,16 @@ public class LocationSettings extends LocationSettingsBase
getActivity().unregisterReceiver(mReceiver); getActivity().unregisterReceiver(mReceiver);
} catch (RuntimeException e) { } catch (RuntimeException e) {
// Ignore exceptions caused by race condition // Ignore exceptions caused by race condition
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Swallowing " + e);
} }
super.onPause(); }
if (mValidListener) {
mSwitchBar.removeOnSwitchChangeListener(this); mSwitchBar.removeOnSwitchChangeListener(this);
mValidListener = false; mValidListener = false;
} }
super.onPause();
}
private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) { private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
// If there's some items to display, sort the items and add them to the container. // If there's some items to display, sort the items and add them to the container.