Android programming implements the method of refreshing the data list of another activity in the activity

This example describes the method of Android programming to refresh the data list of another activity in the activity. Share with you for your reference, as follows:

There is such a problem in Android project: there are two activities, one displays the friend list and the other displays the session list. Now the problem is to add a friend adding function in the session interface. After adding friends, it is required to refresh the friend list in real time.

After thinking about it, I found two ways

Method 1: declare the activity (friendactivity) to be refreshed as a static variable, and then call the refresh method directly in an activity (sessionactivity)

Declare static variables in friendactivity

Directly call the refresh friend list method in friendactivity in sessionactivity:

Of course, this method uses static variables, and you need to release memory in time.

The second method: use the broadcast mechanism to broadcast when adding friends in sessionactivity, and receive broadcast messages through dynamic registration in friendactivity. When receiving messages, update them in friendactivity

Broadcast when sessionactivity adds friends:

Broadcast messages through dynamic registration in friendactivity

This is a good way to refresh the data list of another activity in real time in one activity, which is more flexible and convenient.

Finally, don't forget to destroy the registration

More readers interested in Android related content can view the special topics of this site: activity operation skills summary of Android programming, introduction and advanced tutorial of Android development, Android resource operation skills summary, Android database operation skills summary, Android view skills summary and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>