My application (single activity application) gets stuck on every second start and freezes until an ANR-Dialog shows up. The behaviour is as follows:
First time I click the app icon -> everything works fine. The app starts normally.
I then close the app from recents (swipe the app away in the recents section)
Second time I click the app icon -> The App only shows the App-Icon on a white background but nothing else happens until an ANR-Dialog shows up .
I added logging to see what is going on (see below). #1 is the start of a function and #2 is the end of a function. On the second start I see that BaseActivity.onPause and BaseActivity.onDestroy are getting called but i.e. the App and the BaseActivity are not running into onCreate
Good Case
2025-07-09 08:31:15.921 12280-12280 App Freeze pid-12280 V App.onCreate #1
2025-07-09 08:31:15.921 12280-12280 App Freeze pid-12280 V App.onCreate #2
2025-07-09 08:31:16.102 12280-12280 App Freeze pid-12280 V App.onCreate #3
2025-07-09 08:31:16.168 12280-12280 App Freeze pid-12280 V BaseActivity.onCreate #1
2025-07-09 08:31:16.179 12280-12280 App Freeze pid-12280 V MainActivity.onCreate #1
2025-07-09 08:31:16.305 12280-12280 App Freeze pid-12280 V MainActivity.onCreate #2
2025-07-09 08:31:16.309 12280-12280 App Freeze pid-12280 V SplashFragment.onCreateView #1
2025-07-09 08:31:16.351 12280-12280 App Freeze pid-12280 V SplashFragment.onCreateView #2
2025-07-09 08:31:16.351 12280-12280 App Freeze pid-12280 V SplashFragment.onViewCreated #1
2025-07-09 08:31:16.357 12280-12280 App Freeze pid-12280 V BaseActivity.provideModules #1
2025-07-09 08:31:16.364 12280-12280 App Freeze pid-12280 V BaseActivity.provideModules #2
---------------------------- PROCESS STARTED (12280) for package com.my.package ----------------------------
2025-07-09 08:31:16.365 12280-12280 App Freeze pid-12280 V SplashFragment.onViewCreated #2
2025-07-09 08:31:16.373 12280-12280 App Freeze pid-16489 V SyncForegroundService.onStartCommand #1
2025-07-09 08:31:16.379 12280-12280 App Freeze com.my.package V BaseActivity.onResume #1
2025-07-09 08:31:16.395 12280-12280 App Freeze com.my.package V MainActivity.onResume #1
2025-07-09 08:31:16.395 12280-12280 App Freeze com.my.package V MainActivity.onResume #2
2025-07-09 08:31:16.397 12280-12280 App Freeze com.my.package V BaseFragment.onResume #1
2025-07-09 08:31:16.405 12280-12280 App Freeze com.my.package V BaseFragment.onResume #2
2025-07-09 08:31:16.405 12280-12280 App Freeze com.my.package V SplashFragment.onResume #1
2025-07-09 08:31:16.405 12280-12280 App Freeze com.my.package V SplashFragment.onResume #1
Bad Case
after closing the App in recents and starting the app via app icon I see only onPause, onDestroy but nothing else.
2025-07-09 09:02:24.509 16489-16489 App Freeze com.my.package V BaseActivity.onPause #1
2025-07-09 09:02:24.514 16489-16489 App Freeze com.my.package V BaseActivity.onPause #2
2025-07-09 09:02:24.975 16489-16489 App Freeze com.my.package V BaseActivity.onDestroy #1
2025-07-09 09:02:24.975 16489-16489 App Freeze com.my.package V BaseActivity.onDestroy #2
Here is my ANR Report from the logs
2025-07-09 21:09:44.801 1000-19981 ActivityManager system_server E ANR in com.my.package
PID: 18371
Reason: executing service com.my.package/com.my.package.component.service.SyncForegroundService
ErrorId: 871ac452-4535-4335-a546-8519efa052db
Frozen: s[false] g[false]
Load: 13.77 / 13.87 / 13.36
------ Current CPU Core Info ------
- offline :
- online : 0-7
- AP Temp = 350
0 1 2 3 4 5 6 7
------------------------------------------------------------------------------------------------------------------
scaling_cur_freq 2002000 2002000 2002000 2002000 2002000 2002000 2002000 2002000
scaling_governor energy_awareenergy_awareenergy_awareenergy_awareenergy_awareenergy_awareenergy_awareenergy_aware
scaling_max_freq 2002000 2002000 2002000 2002000 2002000 2002000 2002000 2002000
------------------------------------------------------------------------------------------------------------------
----- Output from /proc/pressure/memory -----
some avg10=0.00 avg60=0.03 avg300=0.19 total=29726724
full avg10=0.00 avg60=0.01 avg300=0.01 total=5610814
----- End output from /proc/pressure/memory -----
----- Output from /proc/pressure/cpu -----
some avg10=1.05 avg60=3.44 avg300=5.06 total=177895467
----- End output from /proc/pressure/cpu -----
----- Output from /proc/pressure/io -----
some avg10=0.00 avg60=0.03 avg300=0.12 total=24417473
full avg10=0.00 avg60=0.01 avg300=0.00 total=8255853
----- End output from /proc/pressure/io -----
Here are some config infos
compileSdk 35
targetSdkVersion 34
koin 3.3.2
gradle plugin 8.6.1
gradle 8.13
kotlin 2.0.21
I found the problem. A very good friend of mine had the idea to use the ANR Watchdog from SalomonBrys to get the logs I was missing to find the problem. Check it out https://github.com/SalomonBrys/ANR-WatchDog.
The WatchDog revealed that an infinity loop existed in an old part of the App. That loop created preasure on the main thread. After removing the loop everything works as expected and I can sleep again.
Thanks to everyone for suggesting and putting your thoughts into this.