How to implement real-time UI updates in Android---need to consider power and traffic

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.