BroadcastReceiver的的onReceive超时BroadcastReceiver、onReceive

2023-09-05 07:17:59 作者:像条狗

我对的BroadcastReceiver ,而在的onReceive()我做我需要做的。

I extend BroadcastReceiver, and in onReceive() I do whatever I need to do.

的onReceive()有一个超时,从文档:

onReceive() has a timeout, from the documentation:

有10秒的超时那   该系统允许后再考虑   接收机要阻挡和   候选人被杀害

there is a timeout of 10 seconds that the system allows before considering the receiver to be blocked and a candidate to be killed

这将创建一个问题,当我在调试模式。我需要10秒以上(有时)。如果我不这样做我所有的调试在10秒内我会关闭连接并调试停止。

This creates a problem when I am in debug mode. I need more than 10 seconds (sometimes). If I don't do all my debugging in 10 seconds my connection is closed and debugging is stopped.

我可以增加超时或禁用调试目的?

Can I increase the timeout or disable it for debugging purposes?

感谢。

推荐答案

在为prevent从力收你的应用程序,而你是暂停在调试过程中一个破发点,尝试安装在开发工具的应用并启用的调试应用程序设置它:

In order to prevent your app from force closing while you are paused on a break point during debugging, try installing the Dev Tools application and enable the Debug App setting which:

让您选择应用程序   调试。你并不需要将其设置为   附加一个调试器,但是设置这个   价值有两个作用:

Lets you select the application to debug. You do not need to set this to attach a debugger, but setting this value has two effects:   将prevent的Andr​​oid从抛出一个错误,如果你停留在   断点很长一段时间,而   调试。    It will prevent Android from throwing an error if you pause on a breakpoint for a long time while debugging.

所有的细节在这里: http://developer.android.com /tool​​s/debugging/debugging-devtools.html

如果你正在做的事情在你的的onReceive 的方法,然后再考虑让你的的BroadcastReceiver 开始的服务并传递下去它在的onReceive 。那么服务可以做再处理。

If you are doing something complicated in your onReceive method, then consider having your BroadcastReceiver start a Service and pass along the data it gets from within onReceive. The Service can then do the longer processing.

 
精彩推荐