I have checkbox in preferences. I want to keep screen on if checkbox is checked and not to keep screen on if checkbox is not checked.
I want something like this:
boolean keepScreen = sharedPrefs.getBoolean("chck_screen", false);
if (keepScreen.equals(false)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
Please, help.
If you are using a PreferenceActivity and have the checkbox declared in XML with the key “checkbox_preference” (rename it to whatever you have) you can do this:
pref.isChecked(); returns if it is checked or not
Additionally, you can set a listener for whenever the value is changed