How can Android update the current UI when it receives a push in BroadcastReceiver?
ringa_lee
ringa_lee 2017-05-24 11:37:50
0
3
981

Use Xiaomi Push.

Then I received the information pushed to me by Xiaomi in the class integrated with BroadcastReceiver, but I want to update the unread readings on the UI at the same time. What should I do?

ringa_lee
ringa_lee

ringa_lee

reply all(3)
洪涛

Bring the data and send a broadcast of your own app to the corresponding UI class that needs to be processed

过去多啦不再A梦

I don’t know if the unread information on the UI you are talking about refers to the icon in the upper right corner of the launcher or the unread information on the UI in the app. The former has nothing to do with the developer. Domestic manufacturers’ systems will automatically count the number of notifications received by the app. , if the latter is the case, perform corresponding operations by parsing the message in the onReceivePassThroughMessage(Context context, MiPushMessage message) method

    @Override
    public void onReceivePassThroughMessage(Context context,MiPushMessage message){
        mMessage=message.getContent();
        if(mMessage != null){
          //更新消息数目
        }
    }

There are many ways to update the number of messages, just choose the appropriate one. For example, it can be passively displayed: maintain a sharedPreference msgCout, get msgCount on the corresponding page and display it on the UI; or active display: you can register a broadcast on the interface where you want to display the number of messages, and send messages to this broadcast in the above code, or you can use EventBus Send messages and more

世界只因有你

BroadcastReceiver doing time-consuming operations will cause ANR, and there is no way to directly modify the UI. In our project, RxBus is used to notify UI updates. Generally speaking, EventBus can be used, and the Sp mentioned above can also be used, but this You will not modify the UI directly, but you need to refresh it manually. If you use the MVP architecture, you can directly adjust the method update in the presenter

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!