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?