Avoid removing switch even listener multiple times
- Fix b/16118646 Change-Id: I36cdc5c8d98dfb63924737af40efff35b9ca2e66
This commit is contained in:
@@ -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,21 +75,17 @@ 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();
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
if (!mValidListener) {
|
||||||
mValidListener = true;
|
mSwitchBar.addOnSwitchChangeListener(this);
|
||||||
|
mValidListener = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,10 +94,15 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mValidListener) {
|
||||||
|
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||||
|
mValidListener = false;
|
||||||
}
|
}
|
||||||
super.onPause();
|
super.onPause();
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
|
||||||
mValidListener = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
|
private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
|
||||||
|
Reference in New Issue
Block a user