即使我的应用程序在 Android 后台运行,如何接收广播事件
我有一个应用程序,它是一个单一活动应用程序,它监听许多广播事件,我的问题是,即使我的应用程序不在前台并且正在运行,我如何确保收到我为我的应用程序添加的所有触发意图在后台??
有没有某种方法 我应该添加我的意图过滤器并且 注册接收器?我敢肯定 如果我把它放在里面,它就不起作用 “Oncreate”
有什么想法或帮助吗?
I have a app which is a single activity app , it listens to many broadcast event , my question is that how can I ensure that I receive all the fired intent which i have added for my app even when my app is not in foreground and running in background ??
is there a certain method where
I should add my intent filter and
do the registerReciever ? I'm sure
it won't work if I keep it in
"Oncreate"
any ideas or help ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想在“后台”时使用 BroadcastReceiver 来接收事件。这将拾取实际广播的事件,而无需启动 UI。
您可以在应用程序的清单中设置 BroadcastReceiver 及其意图过滤器,这样您就不必依赖运行的任何 java 代码来注册接收器。
It sounds like you want to be using a BroadcastReceiver to pick up the events when you are in the 'background'. This will pick up events which are actually broadcast without having to launch a UI.
You can set up the BroadcastReceiver and its intent filters in the manifest for your application, this way you dont have to rely on any java code being run to register the receivers.