[英]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**/
}
當廣播接收器從服務器獲取推送消息時,通知我的應用程序的最佳實踐是什么?
- 編輯 -
通過最佳實踐,我的意思是將消息發送(而不更改應用程序中的消息處理邏輯)到應用程序進行處理的最佳方法。
這可能會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.