user2892437
user2892437

Reputation: 1261

Android - uncheck a SwitchPreference when it has been toggled on?

I essentially want to do the following:

 switch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Boolean newVal = (Boolean) newValue;
                if (newVal && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
                    switch.setChecked(false);
                    displaySettingsDialog(); 
                    return true;
                }

switch.setChecked(false); does not appear to execute, and the switch will toggle on while displaySettingsDialog() happens. How do I get around this?

Upvotes: 0

Views: 448

Answers (1)

user2892437
user2892437

Reputation: 1261

The solution is to return false; instead of true

Upvotes: 0

Related Questions