i have a music player app, and when i pause the current playing song, return to the MainActivity and change the android theme, it crashes.
i can solve the problem by adding android:configChanges="uiMode" in the manifest, but it's not the behavior that i want, because it prevent the user to change the theme of the app.
this is what shows in the logcat the moment i click to change the theme to when the app crashes:
2022-10-15 10:39:18.410 5094-5094 QSControlScrollView pid-5094 D onInterceptTouchEvent 0 return false
2022-10-15 10:39:18.498 5094-5094 QSControlScrollView pid-5094 D onInterceptTouchEvent 1 return false
2022-10-15 10:39:18.500 5094-5094 QSTile.NightModeTile pid-5094 D send click msg
2022-10-15 10:39:18.500 5094-5750 QSTile.NightModeTile pid-5094 D handleClick: from: true, to: false
2022-10-15 10:39:18.511 749-875 SurfaceFlinger pid-749 E Attempt to set layer stack on layer with parent (MiuiColorAnimFade#0) is invalid
2022-10-15 10:39:18.543 2089-2089 SettingsProvider pid-2089 V Notifying for 0: content://settings/secure/ui_night_mode
2022-10-15 10:39:18.544 2089-2089 SettingsProvider pid-2089 V Notifying for 0: content://settings/system/dark_mode_enable
2022-10-15 10:39:18.545 2089-2150 WindowManager pid-2089 D updateContrast : content://settings/system/dark_mode_enable
2022-10-15 10:39:18.545 2089-2150 WindowManager pid-2089 I updateContrastOverlay, darkmode: true isContrastEnabled: false alpha: 0.0
2022-10-15 10:39:18.545 29557-31608 AudioManager pid-29557 D getStreamVolume isRestricted mode = 0
2022-10-15 10:39:18.546 2089-2089 SettingsProvider pid-2089 V Notifying for 0: content://settings/system/smart_dark_enable
2022-10-15 10:39:18.546 2089-2117 ActivityTaskManager pid-2089 I Config changes=200 {1.0 724mcc10mnc [pt_BR] ldltr sw392dp w392dp h774dp 440dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2340) mAppBounds=Rect(0, 79 - 1080, 2210) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=undefined mAlwaysOnTop=undefined mRotation=ROTATION_0} s.2799 themeChanged=0 themeChangedFlags=0 extraData = Bundle[{}]}
2022-10-15 10:39:18.548 29557-31608 chatty pid-29557 I uid=10393(com.tombayley.volumepanel) Binder:29557_6 identical 1 line
2022-10-15 10:39:18.549 29557-31608 AudioManager pid-29557 D getStreamVolume isRestricted mode = 0
2022-10-15 10:39:18.552 9879-11237 AiAiEcho com...onquinn.app.pixelambientmusic I Settings changed for uri: content://settings/secure/ui_night_mode
2022-10-15 10:39:18.554 29557-31608 AudioManager pid-29557 D getStreamVolume isRestricted mode = 0
2022-10-15 10:39:18.657 2089-2117 ActivityTaskManager pid-2089 I Override config changes=200 {1.0 724mcc10mnc [pt_BR] ldltr sw392dp w392dp h774dp 440dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 2340) mAppBounds=Rect(0, 79 - 1080, 2210) mWindowingMode=fullscreen mDisplayWindowingMode=fullscreen mActivityType=undefined mAlwaysOnTop=undefined mRotation=ROTATION_0} s.2799 themeChanged=0 themeChangedFlags=0 extraData = Bundle[{}]} for displayId=0
2022-10-15 10:39:18.580 29557-31608 chatty pid-29557 I uid=10393(com.tombayley.volumepanel) Binder:29557_6 identical 9 lines
2022-10-15 10:39:18.581 29557-31608 AudioManager pid-29557 D getStreamVolume isRestricted mode = 0
2022-10-15 10:39:18.695 5518-5518 NotifierManager pid-5518 D maml dark mode 2
2022-10-15 10:39:18.704 4982-4982 TouchInteractionService pid-4982 D onConfigurationChanged
2022-10-15 10:39:18.704 4982-4982 TouchInteractionService pid-4982 D preloadOverview: mIsUserUnlocked=true homePackageName=com.mi.android.globallauncher
2022-10-15 10:39:18.748 25002-25002 ocessService0:0 pid-25002 W type=1400 audit(0.0:139350): avc: denied { search } for name="theme" dev="dm-1" ino=2228235 scontext=u:r:isolated_app:s0:c512,c768 tcontext=u:object_r:theme_data_file:s0 tclass=dir permissive=0
2022-10-15 10:39:18.895 2089-2150 system_server pid-2089 W Long monitor contention with owner Binder:2089_2 (2117) at boolean com.android.server.wm.ActivityTaskManagerService.updateConfiguration(android.content.res.Configuration)(ActivityTaskManagerService.java:4624) waiters=0 in void com.android.server.wm.WindowManagerService.openSurfaceTransaction() for 350ms
2022-10-15 10:39:18.896 25383-25383 ActivityThread com.example.bloom W SCHED: com.example.bloom/.MainActivity [84, r=557ms, a=103ms, w=2671ms]
2022-10-15 10:39:18.898 5094-5750 BpBinder pid-5094 W Slow Binder: BpBinder transact took 398 ms, interface=android.app.IUiModeManager, code=4 oneway=false
2022-10-15 10:39:18.898 5094-5989 BpBinder pid-5094 W Slow Binder: BpBinder transact took 355 ms, interface=android.app.IUiModeManager, code=5 oneway=false
2022-10-15 10:39:18.900 5094-5750 QSTile.NightModeTile pid-5094 D night mode changed.
2022-10-15 10:39:18.901 5094-5951 BpBinder pid-5094 W Slow Binder: BpBinder transact took 348 ms, interface=android.app.IUiModeManager, code=5 oneway=false
2022-10-15 10:39:18.907 2089-2389 MiuiFreeFo...Controller pid-2089 D displayConfigurationChange
2022-10-15 10:39:18.908 2089-2289 FileUtils pid-2089 W Slow Operation: fsync took 161ms
2022-10-15 10:39:18.909 2089-2389 MiuiFreeFo...ntListener pid-2089 D updateScreenParams ori:1 mNotchBar:0 mDisplayRotation:0isNotchScreen:true
2022-10-15 10:39:18.909 2089-2389 MiuiFreeFo...Controller pid-2089 D displayConfigurationChange
2022-10-15 10:39:18.910 2089-2150 WindowManager pid-2089 I hideContrastOverlay
2022-10-15 10:39:18.911 2089-2389 MiuiFreeFo...ntListener pid-2089 D updateScreenParams ori:1 mNotchBar:0 mDisplayRotation:0isNotchScreen:true
2022-10-15 10:39:18.916 2089-4237 system_server pid-2089 W Long monitor contention with owner Binder:2089_2 (2117) at void com.android.server.UiModeManagerService.setNightModeLocked(int, int)(UiModeManagerService.java:1201) waiters=1 in int com.android.server.UiModeManagerService$12.getNightMode() for 348ms
2022-10-15 10:39:18.917 5094-5094 BpBinder pid-5094 W Slow Binder: BpBinder transact took 370 ms, interface=android.app.IUiModeManager, code=5 oneway=false
2022-10-15 10:39:18.927 2089-4897 MediaFocusControl pid-2089 I abandonAudioFocus() from uid/pid 10392/25383 clientId=android.media.AudioManager@a7203bccom.example.bloom.MusicaKt$$ExternalSyntheticLambda0@24fe664
2022-10-15 10:39:18.929 25383-25383 MediaPlayer com.example.bloom V resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
2022-10-15 10:39:18.929 25383-25383 MediaPlayer com.example.bloom V cleanDrmObj: mDrmObj=null mDrmSessionId=null
2022-10-15 10:39:18.929 1365-1660 NuPlayerDriver pid-1365 D reset(0xef95e300) at state 6
2022-10-15 10:39:18.930 10437-10437 TouchAssistant pid-10437 D onReceive action: android.intent.action.CONFIGURATION_CHANGED
2022-10-15 10:39:18.930 10437-10437 TouchAssistant pid-10437 D onReceive action: android.intent.action.CONFIGURATION_CHANGED handle completed.
2022-10-15 10:39:18.930 1365-25446 AudioTrack pid-1365 V pause(12172): prior state:STATE_PAUSED
2022-10-15 10:39:18.930 1365-25446 AudioTrack pid-1365 V flush(12172): prior state:STATE_PAUSED
2022-10-15 10:39:18.931 1365-25446 AudioTrack pid-1365 V stop(12172): prior state:STATE_FLUSHED
2022-10-15 10:39:18.931 1365-25446 AudioTrack pid-1365 V ~AudioTrack(12172), releasing session id 62849 from 1365 on behalf of 25383
2022-10-15 10:39:18.932 746-29564 AudioFlinger pid-746 V releasing 62849 from 1365 for 25383
2022-10-15 10:39:18.932 746-29564 AudioFlinger pid-746 V decremented refcount to 0
2022-10-15 10:39:18.932 746-29564 AudioFlinger pid-746 V purging stale effects
2022-10-15 10:39:18.940 1365-25443 NuPlayerDriver pid-1365 D notifyResetComplete(0xef95e300)
2022-10-15 10:39:18.940 746-969 APM_AudioPolicyManager pid-746 D closeOutput(11925)
2022-10-15 10:39:18.940 1365-1660 AMessage pid-1365 W failed to post message as target looper for handler 0 is gone.
2022-10-15 10:39:18.940 2089-2089 zhoumingliang pid-2089 D isinvrtest==false
2022-10-15 10:39:18.941 697-8020 audio_hw_primary pid-697 D out_set_parameters: enter: usecase(3: compress-offload-playback) kvpairs: routing=0
2022-10-15 10:39:18.942 746-970 AudioFlinger pid-746 V releasing 62849 from 25383 for -1
2022-10-15 10:39:18.942 746-970 AudioFlinger pid-746 V decremented refcount to 0
2022-10-15 10:39:18.942 746-970 AudioFlinger pid-746 V purging stale effects
2022-10-15 10:39:18.943 746-968 AudioFlinger pid-746 V setParameters(): io 11925, keyvalue closing=true, calling pid 746 calling uid 1041
2022-10-15 10:39:18.943 746-968 AudioFlinger pid-746 V setParameters: filtered keyvalue closing=true
2022-10-15 10:39:18.944 697-8020 audio_hw_primary pid-697 D out_set_parameters: enter: usecase(3: compress-offload-playback) kvpairs: closing=true
2022-10-15 10:39:18.944 746-1207 AudioFlinger pid-746 V removeClient_l() pid 25383, calling pid 746
2022-10-15 10:39:18.944 746-969 AudioFlinger pid-746 V closeOutput() 11925
2022-10-15 10:39:18.946 697-8020 audio_hw_primary pid-697 D out_set_parameters: enter: usecase(3: compress-offload-playback) kvpairs: exiting=1
2022-10-15 10:39:18.946 697-8020 audio_hw_primary pid-697 D copl(0xed0d7800):calling compress flush
2022-10-15 10:39:18.947 697-25448 audio_hw_primary pid-697 D copl(0xed0d7800):out of compress_wait
2022-10-15 10:39:18.948 25383-25383 m.example.bloo com.example.bloom I System.exit called, status: 1
2022-10-15 10:39:18.948 25383-25383 AndroidRuntime com.example.bloom I VM exiting with result code 1, cleanup skipped.
2022-10-15 10:39:18.949 697-8020 audio_hw_primary pid-697 D copl(0xed0d7800):out of compress flush
2022-10-15 10:39:18.951 697-8020 audio_hw_primary pid-697 D out_standby: enter: stream (0xed0d7800) usecase(3: compress-offload-playback)
2022-10-15 10:39:18.951 697-8020 audio_hw_primary pid-697 D copl(0xed0d7800):standby
2022-10-15 10:39:18.988 697-25454 offload_visualizer pid-697 D thread exit
2022-10-15 10:39:18.989 697-8020 audio_hw_primary pid-697 D disable_audio_route: reset and update mixer path: compress-offload-playback speaker
2022-10-15 10:39:18.989 697-8020 soundtrigger pid-697 E audio_extn_sound_trigger_update_stream_status: invalid input device 0x0, for event 2
2022-10-15 10:39:18.989 697-8020 soundtrigger pid-697 D audio_extn_sound_trigger_update_stream_status: uc_info->id 3 of type 0 for Event 2, with Raise=1
2022-10-15 10:39:18.989 697-8020 sound_trigger_hal pid-697 D sound_trigger_hw_call_back event 2 rx_concurrency_active 1, tx_concurrency_active 0, screen on 1, music on 1
2022-10-15 10:39:18.989 697-8020 sound_trigger_hal pid-697 D pcm_transfer_to_barge_in barge in 1, state 0, force idle 0
2022-10-15 10:39:18.989 697-8020 sound_trigger_hal pid-697 D pcm_transfer_to_barge_in exit barge in 0, state 0, force idle 0
2022-10-15 10:39:18.989 697-8020 sound_trigger_hal pid-697 D sound_trigger_hw_call_back rx_concurrency_active 0, tx_concurrency_active 0, screen on 1, music on 0
2022-10-15 10:39:18.989 697-8020 msm8974_platform pid-697 D platform_split_snd_device: snd_device(2) num devices(0) new_snd_devices(0)
2022-10-15 10:39:18.989 697-8020 msm8974_platform pid-697 I platform_get_custom_mtmx_params: no matching param with id 0 ip_ch 2 op_ch 2 uc_id 3 snd_dev 2
2022-10-15 10:39:18.989 697-8020 msm8974_platform pid-697 E platform_get_snd_device_name_extn: device_name=,snd_device=2, device_table[snd_device]=speaker
2022-10-15 10:39:18.989 697-8020 hardware_info pid-697 D hw_info_append_hw_type : device_name = speaker
2022-10-15 10:39:18.989 697-8020 audio_hw_primary pid-697 D disable_snd_device: snd_device(2: speaker)
2022-10-15 10:39:18.989 697-8020 audio_hw_spkr_dsm pid-697 E audio_extn_spkr_dsm_stop_processing: Entry
2022-10-15 10:39:18.994 697-8020 audio_hw_spkr_dsm pid-697 E audio_extn_spkr_dsm_stop_processing: Exit
2022-10-15 10:39:18.994 697-8020 msm8974_platform pid-697 D platform_split_snd_device: snd_device(2) num devices(0) new_snd_devices(0)
2022-10-15 10:39:18.994 697-8020 soundtrigger pid-697 I audio_extn_sound_trigger_update_device_status: device 0x2 of type 0 for Event 0, with Raise=0
2022-10-15 10:39:18.994 697-8020 audio_hw_primary pid-697 D audio_enable_asm_bit_width_enforce_mode: DSP bitwidth feature is disabled.
2022-10-15 10:39:18.994 697-8020 audio_hw_primary pid-697 D out_standby: exit
2022-10-15 10:39:18.995 697-15631 audio_hw_primary pid-697 D adev_close_output_stream: enter:stream_handle(compress-offload-playback)
2022-10-15 10:39:18.995 697-15631 audio_hw_primary pid-697 D out_standby: enter: stream (0xed0d7800) usecase(3: compress-offload-playback)
2022-10-15 10:39:18.995 697-15631 audio_hw_primary pid-697 D out_standby: exit
2022-10-15 10:39:19.005 2089-3551 ConnectivityService pid-2089 D ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ TRACK_DEFAULT id=7380, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED Uid: 10392] ], android.os.BinderProxy@fe4e846)
2022-10-15 10:39:19.005 746-1207 AudioFlinger pid-746 V 25383 died, releasing its sessions
2022-10-15 10:39:18.998 746-746 Binder:746_A pid-746 W type=1400 audit(0.0:139352): avc: denied { write } for name="logd" dev="tmpfs" ino=534 scontext=u:r:audioserver:s0 tcontext=u:object_r:logd_socket:s0 tclass=sock_file permissive=0
2022-10-15 10:39:19.005 746-1207 AudioFlinger pid-746 V pid 3213 @ 0
2022-10-15 10:39:19.005 2089-2117 MediaSessionService pid-2089 D Media button session is changed to null
2022-10-15 10:39:19.005 2089-2117 MediaSessionStack pid-2089 D Search one active MediaSession due to mMediaButtonSession is null or inactive
2022-10-15 10:39:19.005 2089-2117 MediaSessionStack pid-2089 D Pick the one at tail as mediaButtonSession
2022-10-15 10:39:19.005 2089-2117 MediaSessionService pid-2089 D Media button session is changed to com.android.bluetooth/BluetoothMediaBrowserService (userId=0)
2022-10-15 10:39:19.005 2089-2330 ConnectivityService pid-2089 D releasing NetworkRequest [ TRACK_DEFAULT id=7380, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED Uid: 10392] ] (release request)
2022-10-15 10:39:19.005 2089-6606 MediaFocusControl pid-2089 I AudioFocus removeFocusStackEntryOnDeath(): removing entry for android.os.BinderProxy@f606a07
2022-10-15 10:39:19.006 2089-2117 ActivityManager pid-2089 I Process com.example.bloom (pid 25383) has died: fore TOP
2022-10-15 10:39:19.007 2089-2304 InputDispatcher pid-2089 W channel 'b18126f com.example.bloom/com.example.bloom.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9
2022-10-15 10:39:19.007 579-579 hwservicemanager pid-579 I getTransport: Cannot find entry vendor.qti.hardware.iop@2.0::IIop/default in either framework or device manifest.
2022-10-15 10:39:19.007 2089-2304 InputDispatcher pid-2089 E channel 'b18126f com.example.bloom/com.example.bloom.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2022-10-15 10:39:19.007 2089-7412 WindowManager pid-2089 I WIN DEATH: Window{b18126f u0 com.example.bloom/com.example.bloom.MainActivity}
2022-10-15 10:39:19.008 2089-7412 InputDispatcher pid-2089 W Attempted to unregister already unregistered input channel 'b18126f com.example.bloom/com.example.bloom.MainActivity (server)'
---------------------------- PROCESS ENDED (25383) for package com.example.bloom ----------------------------
2022-10-15 10:39:19.009 1342-1342 Zygote pid-1342 I Process 25383 exited cleanly (1)
2022-10-15 10:39:19.012 2089-2162 libprocessgroup pid-2089 I Successfully killed process cgroup uid 10392 pid 25383 in 5ms
2022-10-15 10:39:19.012 579-579 hwservicemanager pid-579 I getTransport: Cannot find entry vendor.qti.hardware.servicetracker@1.0::IServicetracker/default in either framework or device manifest.
2022-10-15 10:39:19.013 2089-2117 AutoStartManagerService pid-2089 I MIUILOG- Reject RestartService packageName :com.example.bloom uid : 10392
2022-10-15 10:39:19.014 2089-2117 ActivityTaskManager pid-2089 W Force removing ActivityRecord{d74f443 u0 com.example.bloom/.MainActivity t1896}: app died, no saved state
2022-10-15 10:39:19.013 579-579 hwservicemanager pid-579 I getTransport: Cannot find entry vendor.qti.hardware.servicetracker@1.0::IServicetracker/default in either framework or device manifest.
2022-10-15 10:39:19.014 8086-19577 BinderSender pid-8086 D onProcessDied: pid=25383, uid=10392