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?
CodePudding user response:
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>