In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how Android applications add messages to message queues". In daily operations, I believe many people have doubts about how Android applications add messages to message queues. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods, hoping to help you answer the doubts of "how Android applications add messages to message queues". Next, please follow the editor to study!
After the main thread of the application prepares the message queue and enters the message loop, other places can send messages to the message queue.
In Step 30 of the article on source code analysis of the Android application startup process, ActivityManagerService notifies the application by calling the scheduleLaunchActivity function of the ApplicationThread class.
It can load the default Activity of the application, which is defined in the frameworks/base/core/java/android / app/ActivityThread.java file:
[java] view plaincopypublic final class ActivityThread {. Private final class ApplicationThread extends ApplicationThreadNative {. / / we use token to identify this activity without having to send the / / activity itself back to the activity manager. (matters more with ipc) public final void scheduleLaunchActivity (Intent intent, IBinder token, int ident, ActivityInfo info, Bundle state, List pendingResults, List pendingNewIntents, boolean notResumed, boolean isForward) {ActivityClientRecord r = new ActivityClientRecord (); r.token = token; r.ident = ident; r.intent = intent; r.activityInfo = info; r.state = state; r.pendingResults = pendingResults; r.pendingIntents = pendingNewIntents; r.startsNotResumed = notResumed; r.isForward = isForward; queueOrSendMessage (H.LAUNCH_ACTIVITY, r);} }. }
Here, all the relevant parameters are encapsulated into an ActivityClientRecord object r, and then a new message (H.LAUNCH_ACTIVITY) is added to the message queue of the application by calling the queueOrSendMessage function, which is defined in the frameworks/base/core/java/android / app/ActivityThread.java file:
[java] view plaincopypublic final class ActivityThread {. Private final class ApplicationThread extends ApplicationThreadNative {. / / if the thread hasn't started yet, we don't have the handler, so just / / save the messages until we're ready. Private final void queueOrSendMessage (int what, Object obj) {queueOrSendMessage (what, obj, 0,0);} Private final void queueOrSendMessage (int what, Object obj, int arg1, int G2) {synchronized (this) {. Message msg = Message.obtain (); msg.what = what; msg.obj = obj; msg.arg1 = arg1; msg.arg2 = arg2; mH.sendMessage (msg);}}. }. At this point, the study on "how Android applications add messages to the message queue" is over. I hope I can 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.