Detailed explanation of the method of calling each other between the three components of Android activity, service and broadcaster

This article describes the method of calling each other among the three components of activity, service and broadcaster in Android. Share with you for your reference, as follows:

We study two questions,

1. How the service changes a textview of the activity through the broadcaster. (study this problem, considering that after the service obtains the message from the server, it returns the msg to the activity)

2. How an activity calls a method of a service through binder. (study this problem. Considering that the actions interacting with the server are packaged into a service, the activity only presents the interface and calls the method of the service)

The structure diagram is shown as follows:

The renderings are as follows:

Click the "start service" button to start the service, and then change the UI of the activity.

Click the "send msg to server" button to call the service method and display the notificationbar

code:

1. Create a new myservice class and inherit service

2. Create a new mybroadcastreceiver class, which inherits broadcastreceiver and is used to send intent and start the service

3. The newly created mainactivity class is actually an activity used to render the interface

4. Main.xml layout file

5. The manifest file androidmanifest.xml is used to configure components and other information

More readers interested in Android related content can view the special topics of this site: summary of Android debugging skills and solutions to common problems, introduction and advanced tutorial of Android development, summary of Android multimedia operation skills (audio, video, recording, etc.), summary of usage of Android basic components, summary of Android view skills Android layout 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
分享
二维码
< <上一篇
下一篇>>