I'm making an Android application using Kotlin. It contains App Theme color list so the user can select one color from it, and then I save this color in Shared Preferences.
I've done with all Shared Preferences and XML values stuff, and I've succeeded to change the theme smoothly in the settings activity, and when I reopen the application I find the saved color successfully in settings activity.
The problem is: the changes happens on settings activity only, not in the whole app, and if I want to affect all activities I should use setTheme() in each activity's onCreat().
I don't want to do that since my application has many activities.
Is there better approach to achieve that.
I tried to call setTheme() method on Application class, but it doesn't work.
I understand that you don't want to do it in every Activity, but with activities there is no other approach than setting theme in each one of them.
I would suggest you to create abstract parent e.g.
BaseActivityand callsetTheme()here insideonCreate(). Then you will update your activities just to extend theBaseActivityand make sure you are callingsuper.onCreate().It's faster then pasting the code in every activity individually and it's nicer and more scalable solution.