How do Activity and Service communicate in Android
This article mainly explains "how to communicate between Activity and Service in Android". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how Activity and Service communicate in Android.
For Service remote calls, it is usually in different projects, that is, two different processes, so what is the communication mechanism of the process? The fool drew a picture to illustrate it.
When communicating remotely, the Android process will:
1. Generate a main thread.
two。 Generate Looper objects
3. Generate a message queue.
4. Generate a virtual machine object to communicate between Java and C++.
5. The remote communication is realized through the IPC of the CumberCraft + layer.
The so-called inter-process communication: Android realizes the communication between processes through the IBinder interface. MyActivity will call the transact () function of IBinder and call the remote onTransact () function through IPC. Note: by default, if Service, Activity and BroadcastReceiver are in the same project, then these components will be executed in the same process and executed by the main thread. Of course, you can also configure them to execute in different components, such as letting Service run in the Remote process.
At this point, I believe you have a deeper understanding of "how Activity and Service communicate in Android". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!