Hello guys and Happy new year to all!
I'm having a weird trouble in my app which I can't seem to fix. It should be a logic error, but I'm not able to somehow catch it.
Here is my code
public String[] str={"Disabled","Sound Quality Prefered","Bass Prefered","Battery Prefered",};
public int ThemePresetValue = 0;
private int SelectedThemePresetValue = 0;
public void presets() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Select Your Sound Preset");
alertDialog.setNegativeButton("Cancel", null);
alertDialog.setPositiveButton("Select", themePresetDialogPositiveListener);
alertDialog.setSingleChoiceItems(str, ThemePresetValue, PresetListListener);
alertDialog.show();}
DialogInterface.OnClickListener PresetListListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SelectedThemePresetValue = which;
}
};
DialogInterface.OnClickListener themePresetDialogPositiveListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mPreset = "";
ThemePresetValue = SelectedThemePresetValue;
if (ThemePresetValue == 0) {
mPreset = "Disabled";
} else if (ThemePresetValue == 1) {
mPreset = "Sound Quality Prefered";
} else if (ThemePresetValue == 2) {
mPreset = "Bass Prefered";
} else if (ThemePresetValue == 3) {
mPreset = "Battery Prefered";
}
if (mPreset.equals("Disabled")) {
disabler();
} else if (mPreset.equals("Sound Quality Prefered")) {
SoundQPreset();
} else if (mPreset.equals("Bass Prefered")) {
bassPreset();
} else if (mPreset.equals("Battery Prefered")) {
batteryPreset();
}
}
};
The problem is that after I choose one of the presets the choice sticks until the app is closed from multitasking (MainActivity gets restarted or killed). Then if I re-open the app, the choice of dialog is re-set onto 0 ("Disabled").
Why is this happening? Do you have a solution?