繁体   English   中英

Android广播接收器和&App运行状态

[英]Android broadcast receiver && App running status

我在应用程序中使用了第三方推送服务,当从服务器推送消息时,它的后台服务将发送广播,我必须收听,此过程运行良好。 onReceive()函数中,我可以显示通知,也可以静默地做一些工作。 是否显示通知取决于应用程序状态,即:

if(application_is_running){
    if(message_type == chat_message){
        if(chat_activity_is_present){
            /** notification not allowed **/
        }else{
            /** show notification, open the corresponding chat activity on clicking the notification */
        }
    }else{
        /** store the message silently **/
    }
}else{
    /** show notification, and start the app on clicking the notification**/
}

当广播接收器从服务器获取推送消息时,通知我的应用程序的最佳实践是什么?

- 编辑 -

通过最佳实践,我的意思是将消息发送(而不更改应用程序中的消息处理逻辑)到应用程序进行处理的最佳方法。

这可能会有所帮助。

  1. 使用服务:推荐,但我不太喜欢。
  2. 目的:U可以启动您的应用程序并设置标志(例如single top),该标志将检查您的应用程序是否在后台运行,如果是,则将其引入应用程序。 而且,如果您需要静静地执行此操作,则可以启动一个单独的活动,该活动基本上显示一个透明的背景,并在启动时处理意图,然后自行关闭。 但是,当然,我的服务可以使用户体验更好,但是我对服务的了解并不多。

暂无
暂无

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

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