简体   繁体   English

Android广播接收器始终运行

[英]Android broadcast receiver running always

How do I make a broadcast receiver which runs always, from the very start of the device? 我如何使广播接收机从设备一开始就始终运行? Is this possible without starting the application where it is declared? 是否可以在不声明声明的地方启动应用程序?

If not I guess I would have to start my application when the device starts. 如果没有,我想我将在设备启动时启动我的应用程序。 But this probably adds to much overhead and it's unwanted. 但这可能会增加很多开销,这是不必要的。

I want this always runnning broadcast receiver in order to listen always for c2dm notifications. 我希望此始终运行的广播接收器,以便始终侦听c2dm通知。 These should notify the user that there are new messages in the application. 这些应该通知用户应用程序中有新消息。

如果您使用“意图过滤器”将“ BroadcastReceiver”添加到“清单”中以侦听特定意图,则“接收器”在安装时将处于活动状态。

what do you mean "run always" ? 您是什么意思“始终运行”?

if you need something to be alive for a long time , and from the OS bootup , you need to : 如果您需要长时间保持活动的状态,并且需要从操作系统启动中进行操作,则需要:

  1. let the app to be installed only on the internal storage (otherwise it won't work). 让该应用只能安装在内部存储设备上(否则它将无法正常工作)。

  2. set the broadcast receiver to listen to the boot intent . 设置广播接收器以侦听引导意图。

  3. upon receiving the boot intent, start a service and there listen to the intent you wish to listen to. 收到启动意图后,启动服务,然后在此处聆听您想听的意图。

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

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