In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the message handling mechanism of Android application". In the daily operation, I believe that many people have doubts about the message handling mechanism of Android application. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "what is the message handling mechanism of Android application?" Next, please follow the editor to study!
In the queueOrSendMessage function, the parameters passed above are further encapsulated into a Message object msg, and then the message object msg is added to the application message queue through the mH.sendMessage function.
Here mH is a member variable of the ActivityThread class, which is of type H and inherits from the Handler class.
This H class processes the message through its member function handleMessage, which we will see later when we analyze the processing of the message.
It is defined in the frameworks/base/core/java/android/app/ActivityThread.java file:
[java] view plaincopypublic final class ActivityThread {
.
Private final class H extends Handler {
.
Public void handleMessage (Message msg) {
.
Switch (msg.what) {
.
}
.
}
.
}
When was this mH member variable of the ActivityThread class created? When we analyzed the message loop of the application, we mentioned that when the application process starts, it will load the main function of the ActivityThread class. In this main function, an ActivityThread instance will be created in the current process before entering the message loop through the Looper class:
[java] view plaincopypublic final class ActivityThread {. Public static final void main (String [] args) {. ActivityThread thread = new ActivityThread (); thread.attach (false);. }} when you create this instance, its member variable mH is also created: [java] view plaincopypublic final class ActivityThread {. Final H mH = new H ();. }
As mentioned earlier, the H class inherits from the Handler class, so when the H object is created, the constructor of the Handler class is called, which is defined in the frameworks/base/core/java/android/os/Handler.java file:
[java] view plaincopypublic class Handler {. Public Handler () {. MLooper = Looper.myLooper ();. MQueue = mLooper.mQueue;. } final MessageQueue mQueue; final Looper mLooper;. At this point, the study of "what is the message handling mechanism of Android applications" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.