After the android source code environment was completed some time ago, we started to study the communication between threads and processes, because the task at hand is to continuously obtain device events, and then feedback the obtained events to the UI for updates. According to the android design framework, the process for applications to call lower-level services is as follows:
However, for me, the content of the android source code is a little more and cannot be digested ~~ This task mainly uses a similar process.
After learning the source code, we can find that when the source code continuously monitors device events, it will adopt loose and remote control mechanisms, and will wake up the thread through pipelines, message queues, or other methods. However, I do not know this method yet, so according to the degree to which I can implement it, after a slight modification, such:
First, describe 1 and 2:
1. When the event data of the device is successfully obtained in eventnative, the Java method in eventservice is called.
2. After completing step 1, notify the application to update the UI.
Because I do not use the logoff mechanism here, the system cannot help notify the wake-up thread, but this feature exists: After eventnative calls systemnative, thread blocking continues until systemnative successfully obtains the device event and sends the event to eventnative. This blocking is at the kernel level of the system, so it will not affect the interaction operation at the application layer. So I used this feature. When eventnative is blocked, I call the Java code at the frameworks layer to replace the pipeline wake-up in loose. This method is too often integrated and is not conducive to maintenance, but as a prelude to a deep understanding of the source code knowledge ~
The code is not provided for the time being, because tomorrow is the Spring Festival and I want to release these things. Secondly, more importantly, I just wrote my own demo, and I haven't had time to perform more tests and organization. So let's first introduce one of my ideas.
The Chinese New Year is coming. I wish you a happy holiday and a happy reception of red packets. What is the profit of red packets ~~ ^_^ In the new year, we are moving towards a new goal ~~~