In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to start the Android application". Many people will encounter such a dilemma in the operation of actual cases, 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!
When the Android application process starts, it loads the ActivityThread class in the process and executes the main function of this class.
The message loop process of the application is implemented in this main function.
Let's look at the implementation of this function, which is defined in the frameworks/base/core/java/android/app/ActivityThread.java file:
[java] view plaincopypublic final class ActivityThread {. Public static final void main (String [] args) {. Looper.prepareMainLooper ();. ActivityThread thread = new ActivityThread (); thread.attach (false);. Looper.loop ();. Thread.detach ();. }}
This function does two things, one is to create an instance of ActivityThread in the main thread, and the other is to get the main thread into the message loop through the Looper class. Here we only focus on the latter.
First, let's look at the implementation of the Looper.prepareMainLooper function, which is a static member function defined in the frameworks/base/core/java/android/os/Looper.java file:
[java] view plaincopypublic class Looper {. Private static final ThreadLocal sThreadLocal = new ThreadLocal (); final MessageQueue mQueue;. / * Initialize the current thread as a looper. * This gives you a chance to create handlers that then reference * this looper, before actually starting the loop. Be sure to call * {@ link # loop ()} after calling this method, and end it by calling * {@ link # quit ()}. * / public static final void prepare () {if (sThreadLocal.get ()! = null) {throw new RuntimeException ("Only one Looper may be created per thread");} sThreadLocal.set (new Looper ());} / * * Initialize the current thread as a looper, marking it as an application's main * looper. The main looper for your application is created by the Android environment, * so you should never need to call this function yourself. * {@ link # prepare ()} * / public static final void prepareMainLooper () {prepare (); setMainLooper (myLooper ()); if (Process.supportsProcesses ()) {myLooper (). MQueue.mQuitAllowed = false;}} private synchronized static void setMainLooper (Looper looper) {mMainLooper = looper;} / * Return the Looper object associated with the current thread. Returns * null if the calling thread is not associated with a Looper. * / public static final Looper myLooper () {return (Looper) sThreadLocal.get ();} private Looper () {mQueue = new MessageQueue (); mRun = true; mThread = Thread.currentThread ();}. } this is the end of the content of "how to start the Android application". 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.