是否为BroadcastReceiver.onReceive方法中运行的操作定义了任何时间限制?
onReceive()
is called on the main application thread, the same thread that drives your UI. In general, you want onReceive()
to return in under a millisecond, in case your UI is in the foreground, so you do not freeze the UI (aka, have "jank"). There is also a 5-10 second limit, after which Android will basically crash your app.
However, you cannot reliably fork a background thread from onReceive()
, as once onReceive()
returns, your process might be terminated, if you are not in the foreground.
For a manifest-registered receiver, a typical pattern is to have onReceive()
delegate the work to an IntentService
, which has its own background thread and, being a service, tells the OS that your process is still doing some work and should let your process run a bit longer.
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.