android - BroadcastReceiver onReceive超时

标签 android timeout broadcastreceiver

我扩展了 BroadcastReceiver,在 onReceive() 中我做任何我需要做的事情。

onReceive() 有一个超时,来自文档:

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

当我处于 Debug模式时,这会产生问题。我需要超过 10 秒(有时)。如果我没有在 10 秒内完成所有调试,我的连接将关闭并且调试将停止。

我可以增加超时或出于调试目的禁​​用它吗?

谢谢。

最佳答案

为了防止您的应用程序在调试过程中暂停在断点时强制关闭,请尝试安装开发工具应用程序并启用调试应用程序设置:

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:

  • It will prevent Android from throwing an error if you pause on a breakpoint for a long time while debugging.

所有详细信息都在这里:http://developer.android.com/tools/debugging/debugging-devtools.html

如果您在onReceive 方法中做一些复杂的事情,那么请考虑让您的BroadcastReceiver 启动一个Service。并传递它从 onReceive 中获取的数据。 Service 然后可以进行更长的处理。

关于android - BroadcastReceiver onReceive超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4650016/

相关文章:

java - 数据绑定(bind) - EditText 的 maxLength 属性

android - 从 java 类启动 Camera Intent

android - 单击时如何从按钮获取文本?

Java Applet 退出并且托盘图标在一段时间后消失,是否有超时设置?

javascript - 事件监听超时-node.js

Android TextView 以及如何确定可见字符数

android - Android套接字连接超时

android - 在 android PIE 9 中结束通话后来电号码为空

android - 屏幕关闭时重启应用程序

android - 应用程序打开时警报管理器不断触发