I know switching dark mode on android programmatically is easy with below code.
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
I want to know how to do it like whatsapp/slack which won't restart the app. User will still be in preferences fragment and mode changes there right away. If I try above line, my activity is recreated and first fragment is launched but not preference fragment.
How to handle it the way they are handling it?
Put in the manifest
android:configChanges="...|uiMode|..."
for that activity and use a day/night theme, doing so, the switch is automatic and with 0 lines of code