I create an app to periodically set wallpaper. It works fine for Android < 12, from Android 12+ the new feature "Dynamic Color" causes the app's activity restart whenever the wallpaper changed.
If I am in the app and there is currently a dialog showing and the wallpaper is changed, the app will crash with error "android.view.WindowLeaked: Activity [my activity] has leaked window DecorView" if I am doing something with the dialog (reference to old activity instance). It is because of the activity recreation.
I also cannot exclude the activity from configuration changes because it cannot with the Dynamic Color. See the doc Some configuration changes always cause the activity to restart
If I go to Settings -> Wallpaper & Style to disable Dynamic Color, everything go back to normal.
I've many crash reports in Play Console (on Android 13) because of this issue.
How to fix this issue on Android 12, 13+ when Dynamic Color is enabled.