I am working on an app that has a main activity and a settings activity where the user can manually change the theme to dark mode. I implemented and tested this setting change on my Samsung S8 device and it worked fine. However, I then tested it on my Google Pixel 4 and encountered an issue. When navigating back to the main activity (from settings) the previous activity still has the light theme applied for a split second. Then it recreates and applies the dark theme. However, the effect of seeing the white theme flash is a bit jarring.
When the user clicks the button to change the theme in settings, this code block is called:
fun updateTheme(newTheme: Int) {
setDarkModePref(sharedPreferences, newTheme)
AppCompatDelegate.setDefaultNightMode(newTheme)
}
Any idea why the theme might be flashing for Pixel 4 devices only? I figure the Pixel 4 should be less prone to this sort of issue than a Samsung S8 which is slower.