'How to make my app immune to theme change?
Whenever the theme of the device is changed, two things happen:
- The colours change
- The activity is restarted
I don't want any of these to happen. The solutions already posted on Stack Overflow either deal with the first problem or the second one. I have already solved the first problem by deleting the night theme xml file and Theme.MaterialComponents.Light.DarkActionBar instead of DayNight. But I am unable to solve the second problem. The solutions on Stack Overflow are about how we can change the theme without recreating the activity. But what I want is nothing to happen. My activity should not react to theme change. Is there any way to do it?
Solution 1:[1]
In the app AndroidManifest.xml where your Activity is declared. You can set android:configChanges="uiMode"
For example:
<activity
android:name=".MainActivity"
android:configChanges="uiMode"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mayur Gajra |
