Android implements cross process update UI example through remoteviews
1、 Overview
In the previous article, Android implements cross process update UI through Aidl. We learned Aidl cross process update UI. This traditional way to implement cross process update UI is feasible, but it has the following disadvantages:
Next, we implement cross process UI update through remoteviews
2、 Implementation effect diagram
There are two activities in the same application, mainactivity and temp2activity, which are not in the same process.
Now you need to change the view in mainactivity through temp2activity, that is, add two buttons in mainactivity, that is, realize the function of cross process updating UI.
Click "jump to new process activity" in mainactivity to start a temp2activity of a new process. First click "bind service" to start the service, then click "Aidl update" to update the UI across processes by calling handler. Click return. We find that two new buttons have been added to the mainactivity page, And the button also has a click event.
3、 Core code
IremoteViewsManager.aidl
It provides two methods: one is to update the content in textview according to ID, and the other is to add view according to ID
RemoteViewsAIDLService.Java
MainActivity.java
Temp2Activity.java
AndroidManifest.xml
4、 Summary
Remoteviews is designed to update UI across processes. It encapsulates many methods to update UI across processes. However, this does not mean that remoteviews is omnipotent. It also has shortcomings. At present, the supported layouts and views are limited
layout:
FrameLayout LinearLayout RelativeLayout GridLayout
View:
AnalogClock button Chronometer ImageButton ImageView ProgressBar TextView ViewFlipper ListView GridView StackView AdapterViewFlipper ViewStub
Custom views are not supported, so the specific use of remoteviews or Aidl or broadcastreceiver depends on the actual requirements.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.