The use of Messenger in cross-process communication
Pre-stated:
I am also a beginner, so this article is from a beginner's point of view, if there are inappropriate places please leave a message to teach me, thank you.
This article is intended to explain the use of Messenger and the principle of Messenger on the application layer and the Messenger's response on the server.
What is Messenger?
Messenger can be translated as Messenger, Messenger is a lightweight IPC scheme through which you can pass a message object in a different process and put the data that we need to pass in the message to achieve the process of data transfer.
Step one: Use of Messenger
Service-Side authoring:
Configure the service in manifests:
Writing the client (in another application):
Start the activity on the server and turn on the service:
Then start the client and view the test results:
Step Two: The principle analysis of Messenger on the application layer
We follow the creation method of Messenger, to see the source code can be known, the bottom is the use of Aidl:
About the use of aidl and the principle of analysis, here refer to my CSDN blog, which has detailed analysis, Android Basics--The beginner must know aidl on the application layer of the binder mechanism, http://blog.csdn.net/qq_30379689/ article/details/52253413
Step Three: Messenger can accept the client's message after the reply, here is similar to the function of automatic mailbox reply
Android Foundation--messenger in cross-process communication