[英]How to receive broadcast event even when my App is in background in android
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?是否有某种方法我应该添加我的意图过滤器并执行 registerReciever? I'm sure it won't work if I keep it in "Oncreate"如果我将它保存在“Oncreate”中,我相信它不会起作用
any ideas or help??任何想法或帮助?
It sounds like you want to be using a BroadcastReceiver to pick up the events when you are in the 'background'.听起来您想在“后台”中使用 BroadcastReceiver 来接收事件。 This will pick up events which are actually broadcast without having to launch a UI.这将拾取实际广播的事件,而无需启动 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.您可以在应用程序的清单中设置 BroadcastReceiver 及其意图过滤器,这样您就不必依赖任何正在运行的 java 代码来注册接收器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.