When a user opens preferences on my app he may make changes for example changing the app theme.
The documentation for ContextThemeWrapper.setTheme(int)
says:
Set the base theme for this context. Note that this should be called before any views are instantiated in the Context (for example before calling
setContentView(View)
orinflate(int, ViewGroup)
).
So my first thought was restarting the app onResume()
when the user changed the preferences. However I noticed that sometimes the process of restarting the activity is seamless while other times the activity is closed, the home screen is seen and only after some seconds the app opens again.
I'm wondering if there is a way to change handle the preferences changes. Like for instance changing the theme after onResume
without restarting the activity or restarting the activity on the background while the user is on preferences.
What's the right way to handle this?
In the second activity, the back button at the top left can be used to go back to the previous activity.
Activity or dialog appears in foregroundIf a new activity or dialog appears in the foreground, taking focus and completely covering the activity in progress, the covered activity loses focus and enters the Stopped state. The system then, in rapid succession, calls onPause() and onStop() .
Change Activity Type on AndroidGo to your Start tab in the app and locate the grid with 4 boxes at the bottom of the screen. Tap the Activity box and select the activity type you want to track (running, walking, cycling, hiking, etc.).
Assuming that your Preference
screen is an Activity
, when the user navigated to it, MainActivity
was placed on a paused
state (and then probably on a stopped
state). When the user navigates back to MainActivity
onResume()
will be called; here you can change the sate of MainActivity
accordingly to reflect the preferences that were changed.
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