Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42fa9734 authored by Lifu Tang's avatar Lifu Tang
Browse files

Avoid removing switch even listener multiple times

- Fix b/16118646

Change-Id: I36cdc5c8d98dfb63924737af40efff35b9ca2e66
parent b64a1f2f
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
@@ -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,22 +75,18 @@ 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();
        if (!mValidListener) {
            mSwitchBar.addOnSwitchChangeListener(this);
            mValidListener = true;
        }
    }

    @Override
    public void onPause() {
@@ -102,11 +94,16 @@ 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);
            }
        super.onPause();
        }
        if (mValidListener) {
            mSwitchBar.removeOnSwitchChangeListener(this);
            mValidListener = false;
        }
        super.onPause();
    }

    private void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
        // If there's some items to display, sort the items and add them to the container.