简体   繁体   English

当应用程序关闭时广播接收器

[英]Broadcast receiver when application is off android

I am going to implement Download Queue for my application. 我将为我的应用程序实现Download Queue。 One of its feature will be when Network get connected or disconnected. 网络连接或断开连接是其功能之一。 I want to notify my QueueManger(Service) to update items status and stop. 我想通知我的QueueManger(Service)更新项目状态并停止。 I know use of Broadcast Receiver and how to use it. 我知道广播接收器的使用以及使用方法。 My question is if my application is stooped (finished) will broadcast receiver will work? 我的问题是,如果我的应用程序弯曲(完成),广播接收器将正常工作吗? Will it notify application or not? 是否会通知申请?

If not is there any way to achieve this functionality even when application is stooped. 如果没有,那么即使在应用程序弯曲的情况下也无法实现此功能。

If you register your receiver in the XML instead of programmatically, then it should be able to catch these even when the program is not running. 如果您以XML而非编程方式注册接收器,那么即使程序未运行,接收器也应该能够捕获这些接收器。

See question, same solution applies Intent action for network events in android sdk 看到问题,相同的解决方案对Android SDK中的网络事件应用了Intent操作

If you have defined your broadcast receiver as <receiver> in AndroidManifest.xml and listening for android's default action strings, then Yes, it will work . 如果您已在AndroidManifest.xml中将广播接收器定义为<receiver>并侦听android的默认操作字符串,则可以,它将起作用

Otherwise, I would recommend you to make use of Service. 否则,我建议您使用服务。 It can run silently in the background and do all the logic you want. 它可以在后台静默运行,并执行您想要的所有逻辑。 Your service can even be provoked automatically when the phone is restarted (if you code correctly). 重新启动电话后,甚至可以自动激发您的服务(如果编码正确)。

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

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