簡體   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