In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The main content of this article is to explain "what is the use of Android's Looper". 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 "what's the use of Android's Looper"?
Here you tell mEpollFd that it monitors the EPOLLIN event of the mWakeReadPipeFd file descriptor, that is, when there is something to read in the pipe, it wakes up the thread that is currently waiting for the content in the pipe.
After the Looper object of the C++ layer is created, it returns to the constructor of the NativeMessageQueue of the JNI layer, and * * returns to the creation process of the message queue MessageQueue of the Java layer, so that the Looper object of the Java layer is ready. It's a little complicated. Let's summarize what has been done in this step:
a. In the Java layer, a Looper object is created, which is used to enter the message loop, and there is a message queue MessageQueue object mQueue inside it
b. In the JNI layer, a NativeMessageQueue object is created, and this NativeMessageQueue object is stored in the member variable mPtr of the message queue object mQueue in the Java layer
c. In the C++ layer, a Looper object is created and stored in the member variable mLooper of the NativeMessageQueue object in the JNI layer. The function of this object is to make the main thread of the Android application wait when there is no message in the message queue in the Java layer, and when a new message comes to the message queue in the Java layer, it wakes up the main thread of the Android application to process the message.
Next, you use the epoll_ctl function to tell epoll what events to monitor for the corresponding file descriptor:
[cpp] view plaincopystruct epoll_event eventItem
Memset (& eventItem, 0, sizeof (epoll_event)); / / zero out unused members
Of data field union
EventItem.events = EPOLLIN
EventItem.data.fd = mWakeReadPipeFd
Result = epoll_ctl (mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &
EventItem)
Go back to the main function of the ActivityThread class, and after the above work is ready, call the loop function of the Looper class to enter the message loop:
[cpp] view plaincopypublic class Looper {. Public static final void loop () {Looper me = myLooper (); MessageQueue queue = me.mQueue;. While (true) {Message msg = queue.next (); / / might block. If (msg! = null) {if (msg.target = = null) {/ / No target is a magic identifier for the quit message. Return;}. Msg.target.dispatchMessage (msg); Msg.recycle ()}. }
Here is to enter the message loop, which continues to get the next message msg to be processed from the message queue mQueue. If the target member variable of the message is null, it means to exit the message loop, otherwise the dispatchMessage member function of this target object will be called to deal with the message. The type of this target object is Handler. When we analyze the sending of the message, we will see that the message object msg is set.
At this point, I believe you have a deeper understanding of "what is the use of Android's Looper?" 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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.