I'm a beginner at this, so bear with me.
In my app, I want the theme of the app to update based upon user preference. I have a preferences page with a theme section, and here is the code for my MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String userTheme = preferences.getString("theme_setting", "Blue");
if (userTheme.equals("Blue"))
setTheme(R.style.BlueTheme);
else if (userTheme.equals("Red"))
setTheme(R.style.RedTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
//Initiate buttons
quadButton = (Button) findViewById(R.id.quadButton);
sssButton = (Button) findViewById(R.id.sssButton);
ssaButton = (Button) findViewById(R.id.ssaButton);
areaButton = (Button) findViewById(R.id.areaButton);
volumeButton = (Button) findViewById(R.id.volumeButton);
conversionButton = (Button) findViewById(R.id.conversionButton);
buttonListeners();
}
@Override
protected void onResume() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String userTheme = preferences.getString("theme_setting", "Blue");
if (userTheme.equals("Blue"))
setTheme(R.style.BlueTheme);
else if (userTheme.equals("Red"))
setTheme(R.style.RedTheme);
super.onResume();
setContentView(R.layout.activity_main);
//Initiate buttons
quadButton = (Button) findViewById(R.id.quadButton);
sssButton = (Button) findViewById(R.id.sssButton);
ssaButton = (Button) findViewById(R.id.ssaButton);
areaButton = (Button) findViewById(R.id.areaButton);
volumeButton = (Button) findViewById(R.id.volumeButton);
conversionButton = (Button) findViewById(R.id.conversionButton);
buttonListeners();
}
This works when the Up button is pressed to return to the MainActivity from the settings screen, but not when the system back button is pressed. I tried to solve that with the onResume() method but it seems to never actually call onResume during runtime. Also, in Android Studio, it says "Method onResume() is never used"
What is going wrong here? Any help would be appreciated, thanks!