In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the message passing mechanism between Android threads". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. How is the message sent?
This question can also be extended: is the way to send deferred messages delayed insertion or delayed execution? I also wrote the specific answer on the flow chart. Summarize it yourself.
2. How does the message loop work?
We can also know from here that the messages we send through postDelay are not accurately executed.
Suppose that one message takes too long to execute, and by the time it is processed and then the next message is processed, it may have passed the time specified for execution of the next message.
3. How to deal with the distribution of messages?
The process of sending messages is very simple, so there is no drawing. The code on the sacrifice:
The description in words is:
1. When msg.callback is not empty, call back the msg.callback.run () method
2. When the mCallback member variable of handler is not empty, the callback method mCallback.handleMessage (msg) ends directly if true is returned; otherwise, perform step 3
3. Call Handler's own handleMessage (), which is the method we often copy.
Other questions
1. What is the difference between the Looper of the child thread and the Looper of the main thread?
A:
The Looper of the child thread can exit, but the Looper of the main thread cannot exit.
You have to prepare and create the Looper of the child thread yourself, but the Looper of the main thread creates it for you by default.
Talk is cheap, above ~
2. How is MessageQueue created?
A: MesageQueue is created by calling the native method at the bottom, which is essentially a single linked list
3. How is the message delay of Handler realized?
Message queues are sorted by message trigger time (msg.when)
Native wakes up epoll_wait at a specific time by setting its timeout
The precision of delay is actually not high.
That's all for "what is the message passing mechanism between Android threads?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.