简体   繁体   中英

ANR when screen turns off, BroadcastReceiver related issue

The application I am working on, works correctly when the screen is on, and for any length of time, but as soon as the phone goes to sleep and 10 seconds have elapsed, I get an error in my logcat,

I/art Thread[5,tid=318,WaitingInMainSignalCatcherLoop,Thread*=0xaf60e400,peer=0x12c00080,"Signal Catcher"]: reacting to signal 3

I pulled the traces file and tried to understand what was causing this issue and read through androids page on application performance, I have figured out that, it is being caused because a BroadcastReceiver hasn't executed in 10 seconds,

A BroadcastReceiver hasn't finished executing within 10 seconds.

From reading the traces file, I believe it has something to do with the timeout of the screen being broadcast and the action not being completed.

"ActivityManager" prio=5 tid=16 TimedWaiting
 | group="main" sCount=1 dsCount=0 obj=0x12d41970 self=0xac884400
 | sysTid=859 nice=-2 cgrp=apps sched=0/0 handle=0xb50e9e80
 | state=S schedstat=( 443987410679 259509083288 699634 ) utm=18416 stm=25982 core=2 HZ=100
 | stack=0xa14fa000-0xa14fc000 stackSize=1036KB
 | held mutexes=
 at java.lang.Object.wait!(Native method)
 - waiting on <0x03423764> (a com.android.server.am.ActivityManagerService$6)
 at java.lang.Object.wait(Object.java:422)
 at com.android.server.am.ActivityManagerService.dumpStackTraces(ActivityManagerService.java:4969)
 - locked <0x03423764> (a com.android.server.am.ActivityManagerService$6)
 at com.android.server.am.ActivityManagerService.dumpStackTraces(ActivityManagerService.java:4946)
 at com.android.server.am.ActivityManagerService.appNotResponding(ActivityManagerService.java:5187)
 at com.android.server.am.BroadcastQueue$AppNotResponding.run(BroadcastQueue.java:171)
 at android.os.Handler.handleCallback(Handler.java:739)
 at android.os.Handler.dispatchMessage(Handler.java:95)
 at android.os.Looper.loop(Looper.java:135)
 at android.os.HandlerThread.run(HandlerThread.java:61)
 at com.android.server.ServiceThread.run(ServiceThread.java:46)

Can someone please point me in the right direction to resolve this issue? How can I find the root cause of the issue.

What I had tried (in my ignorance) I tried removing all the Broadcast Receivers in the code, that didn't help., obviously. I got rid of the wakeLocks in an attempt to resolve the issue, but that also didn't help.

Any help is greatly appreciated.

I'm having the same problem here with an operation that should not take so much time, but for some reason, it is.

From the official Android Documentation:

The specific constraint on BroadcastReceiver execution time emphasizes what broadcast receivers are meant to do: small, discrete amounts of work in the background such as saving a setting or registering a Notification. So as with other methods called in the UI thread, applications should avoid potentially long-running operations or calculations in a broadcast receiver. But instead of doing intensive tasks via worker threads, your application should start an IntentService if a potentially long running action needs to be taken in response to an intent broadcast .

http://developer.android.com/training/articles/perf-anr.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM