1. If power and flow are not taken into account, simply inherit the runnable in the corresponding activity, write a while loop inside the Run method, call the interface to return the data, and update the UI immediately if the data has changed
2. Need to consider the power, is the remote server to send messages to the client, the client receives information, to send a broadcast, the corresponding activity received the broadcast to update the UI, the broadcast sender is a background service component
A similar question:
----------------------Online has a post, said a handler at the same time to update multiple activity interface, the practice is to write handler as a singleton mode, through the interface callback
This is done by separating the life cycle of the handler from the activity and providing an interface to the handler, each activity being a listener, notifying the activity when the handler data changes
Then in the activity to implement the interface, re-interface inside the method, in the Onresume register, in the OnPause inside write-off,
Registering a socket when acquiring a singleton mode object
You can also let the current application inherit the same base class baseactivity, define a good handler in the base class, and other subclasses can inherit the use,
A similar question:
About using URIs in Android to listen for changes in the database
How to implement real-time UI updates in Android---need to consider power and traffic