kim nicole sabordo
kim nicole sabordo

Reputation: 53

Prevent restarting app when switching theme in android studio

I have a problem with my app that when I toggling the system theme it restart the entire app to the main fragment, How can I prevent this that when switching to dark mode or light it wont restart the entire app.

Upvotes: 5

Views: 1672

Answers (1)

William Amaral
William Amaral

Reputation: 111

I have the same problem, and I spend a lot of time trying to find a solution. Then, I found this article on Medium:

Applying dark mode without recreating your app

You need to specify uiMode on your Activity and handle the theme state changes by yourself.

<activity
android:name=".MyActivity"
android:configChanges="uiMode" />

Upvotes: 4

Related Questions