I have created an application where i can switch between 2 themes( Black and white) by a button click. And I have set default theme as white in the manifest.
So every time the application is closed and restarted, the theme state is not saved and white theme is applied.
Can anyone give me some idea or code if possible, about how to save the state of the application, different methods to do it?
Thank You.
Have a boolean trigger that you check the
SharedPreferences
for. If the boolean is true, set the application to white. If false, black. Every time the user changes the theme he/she wants, save the boolean in theSharedPreferences
.Code Sample:
In onCreate():
In the button's onClick():