I’m attempting to use a Button from view class to turn off sound from app. (ie: mute)
When user pushes box i want code to check if value is already true or flase and then set to opposite using ID called ‘mute’. I think i have the IF part setup, just need easy change SharedPreferences from true to flase and vice versa…
Here is code framework I’m testing(BEFORE):
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean cmute = getPrefs.getBoolean("mute", defValue);
if (cmute == true){
}
if (cmute == false){
}
I have tried various findings for the solution but most are too complex for this simple need I think..
Here is my rework AFTER posted suggestion:
if (cmute == false){
Editor editor = getPrefs.edit();
editor.putBoolean("mute", true);
editor.commit();
Editor editor2 = getPrefs.edit();
editor.putBoolean("notice", true);
editor.commit();
}
if (cmute == true){
Editor editor = getPrefs.edit();
editor.putBoolean("mute", false);
editor.commit();
Editor editor2 = getPrefs.edit();
editor.putBoolean("notice", false);
editor.commit();
}
This can be achieved with the
Editorinterface:That should work for you: