简体   繁体   English

Android Broadcast接收器:在Java代码和清单中注册接收器

[英]Android Broadcast receiver: Registering receiver in java code vs manifest

I am planning to register for few events in my broadcast receiver that is registered in java code (not manifest). 我打算在用Java代码(不是清单)注册的广播接收器中注册一些事件。 I need to listen to these events for the entire lifetime of the application. 我需要在应用程序的整个生命周期内监听这些事件。 In order to receive the events for whole application lifetime, do I need to hold the partial wake lock for entire application lifetime (As I am not registering in manifest) ? 为了接收整个应用程序生命周期中的事件,我是否需要在整个应用程序生命周期中保留部分唤醒锁(因为我未在清单中注册)? Please help. 请帮忙。

If you have an Activity or a Service running and you called registerReceiver() in either one, then you can only expect to continue receiving the broadcasts while the CPU is on. 如果您正在运行“ Activity或“ Service ,并且在其中任何一个中调用了registerReceiver() ,则只能期望在CPU处于打开状态时继续接收广播。

If you want to receive even while the user is not using the device, then yes, you need to use a partial wakelock. 如果即使在用户不使用设备时也要接收,则可以,您需要使用部分唤醒锁。

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

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