我在应用程序中使用了第三方推送服务,当从服务器推送消息时,它的后台服务会发送一个我必须收听的广播,这个过程很正常。在函数中
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**/
}
当广播接收器从服务器收到推送消息时,通知我的应用程序的最佳做法是什么?
--编辑--
通过最佳实践,我指的是将消息发送到应用程序处理的最佳方式(不改变应用程序中的消息处理逻辑)。