简体   繁体   English

屏幕关闭时为ANR,与BroadcastReceiver相关

[英]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, 我正在使用的应用程序可以在屏幕打开且在任何时间段内正常运行,但是一旦手机进入睡眠状态并经过10秒钟,我的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, 我拉出了跟踪文件,试图了解导致此问题的原因,并仔细阅读了androids页面上有关应用程序性能的信息,我发现这是由于BroadcastReceiver在10秒钟内未执行而导致的,

A BroadcastReceiver hasn't finished executing within 10 seconds. BroadcastReceiver在10秒内尚未完成执行。

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: 从官方的Android文档中:

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. 对BroadcastReceiver执行时间的特定限制强调了广播接收器的作用:在后台进行少量分散的工作,例如保存设置或注册Notification。 So as with other methods called in the UI thread, applications should avoid potentially long-running operations or calculations in a broadcast receiver. 因此,与在UI线程中调用的其他方法一样,应用程序应避免在广播接收器中可能长时间运行的操作或计算。 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 . 但是, 如果需要响应潜在的长时间广播而执行长时间运行的操作 ,则应用程序应该启动IntentService ,而不是通过辅助线程来执行繁重的任务。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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