Issue with Lifecycle Callback Order when Using AppCompatDelegate.setDefaultNightMode

13 Views Asked by At

My Activity stack order is: MainActivity, SettingActivity, ThemeSettingActivity. The ThemeSettingActivity is top activity.

When I use AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) and switch themes through the system settings, only the top activity in the stack receives lifecycle callbacks, while MainActivity and SettingActivity do not receive any callbacks.

However, when I switch themes using AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) or AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) in code, if my app is in the foreground, all activities (including the top activity, MainActivity, and SettingActivity) receive lifecycle callbacks, and these callbacks are executed after the lifecycle callbacks of the top activity. The lifecycle callback order of my three activities is as follows:

please help me ~!

I hope the lifecycle callback order to be correct, with the ThemeSettingActivity's onResumed method being called last.

1

There are 1 best solutions below

1
hulala NN On

The lifecycle callback order of my three activities is as follows:

ThemeSettingActivity::onActivityPaused

ThemeSettingActivity::onActivityStopped

ThemeSettingActivity::onActivitySaveInstanceState

ThemeSettingActivity::onActivityDestroyed

ThemeSettingActivity::onActivityCreated

ThemeSettingActivity::onActivityStarted

ThemeSettingActivity::onActivityResumed

SettingActivity::onActivityDestroyed

SettingActivity::onActivityCreated

SettingActivity::onActivityStarted

SettingActivity::onActivityResumed

SettingActivity::onActivityPaused

SettingActivity::onActivityStopped

SettingActivity::onActivitySaveInstanceState

MainActivity::onActivityDestroyed

MainActivity::onActivityCreated

MainActivity::onActivityStarted

MainActivity::onActivityResumed

MainActivity::onActivityPaused

MainActivity::onActivityStopped

MainActivity::onActivitySaveInstanceState