The theme changes in current activity(Settings Activity), but I have to restart the other background activities to apply the new theme. I'm thinking that the background activities should be restarted in the settings activity, but I can't find how.
This is my Settings Activity:
public class SettingsActivity extends FragmentActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
private SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SettingsHelper.onActivityCreateSetTheme(this);
getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
prefs = PreferenceManager.getDefaultSharedPreferences(this);
}
@Override
protected void onResume() {
super.onResume();
prefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
protected void onPause() {
super.onPause();
prefs.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals("theme")) {
boolean isDark = prefs.getBoolean("theme", false);
prefs.edit().putBoolean("theme", isDark).apply();
SettingsHelper.changeToTheme(this);
}
}