I've implemented two simple themes on my app, you can select them inside a SettingsActivity (extending PreferenceActivity).
At this point, when you change theme, it's applied only on the new created activities because the activity from where you called the settings is an old one in the activity stack.
I've searched a lot and I've found this pretty useful: how to restart an activity.
By the way, I'm not completely clear on WHERE put this code. The only way to make it works was to put it in the onRestart() method,
but this is a HUGE wasting of cpu, battery and user experience.
Any help?
Set a PreferenceChangedListener on the theme preference. If it gets fired, clear your user back to the top level of the app. You could just restart the current activity but if you are several activities deep then this becomes a bit of a pain. Easier to just reset the app back to the start.
Intent i = new Intent(this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
this.finish();
this.startActivity(i);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With