I'm getting regular ANR's on my WearOS app regarding the android.intent.action.SCREEN_OFF broadcast, which I haven't registered for.
It happens primarily on Samsung Galaxy Watch4 devices, like the one I am developing on.
The case is complicated and googling didn't help much. Here is the flow, bear with me:
- The app launches normally, works as expected;
- The watch is turned downwards and the screen goes off. So far so good;
- I wait about 20 seconds for the Wear OS to move my app to the background and return to the watch face;
- I see in ADB that the app is running;
- I turn the watch up, the screen turns on and I see the watch face, my app is in the background;
- I turn the watch back down, wait a few seconds and then it crashes with ANR
Reason: Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x50200010 (has extras) }
I've been developing for a while and I know how to read the logs, but I found nothing there that could lead me to what registers for this broadcast and does not respond. The only possible reason I can think of is the imports I am using, which are scarce. Here they are:
dependencies {
implementation 'com.google.android.gms:play-services-wearable:17.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.wear:wear:1.2.0'
implementation 'androidx.core:core-splashscreen:1.0.0-beta01'
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
}
SDK:
minSdk 25
targetSdk 31
I did suspect the splashscreen as closest to the screen and removed it, but the ANR happened nevertheless.
I even tried implementing my own BroadcastReceiver that does not unregister on onPause in order to give some answer to the system, even added this.goAsync().finish(); to its onReceive(), but it didn't help.
Has anyone bumped into this? Any help will be greatly appreciated!