如果SendBroadcast活动或通知 [英] SendBroadcast if Activity or Notification
问题描述
我有一个应用程序,下载在后台服务的数据,我希望能够,如果他们当前正在运行的应用程序更新活动的用户界面或触发通知,如果他们不。
I have an application that downloads data in a background service and I want to be able to update an activity UI if they are currently running the application or trigger a Notification if they are not.
我如何知道如果应用程序目前是在前景?
How do I know if the application is currently in the foreground?
我可以在活动注册一个BroadcastReceiver内部类,如果触发该公司在前台以其他方式使用通知,但我不知道我怎么能检查采取什么行动。
I could register a BroadcastReceiver inner class in the activity and trigger this if its in the foreground otherwise uses notification but I don't know how I can check what action to take.
感谢您的任何答复。
推荐答案
使用一个有序的广播,与该活动实施高优先级的的BroadcastReceiver
和一个独立的低优先级的BroadcastReceiver
提高通知
。我有一个博客帖子涉及这一具体议题
Use an ordered broadcast, with the activity implementing a high-priority BroadcastReceiver
and a separate low-priority BroadcastReceiver
to raise the Notification
. I have a blog post covering this specific topic.
这篇关于如果SendBroadcast活动或通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!