日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
Android應(yīng)用程序啟動(dòng)是怎么實(shí)現(xiàn)的

本篇內(nèi)容介紹了“Android應(yīng)用程序啟動(dòng)是怎么實(shí)現(xiàn)的”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

成都創(chuàng)新互聯(lián)公司是一家專(zhuān)業(yè)從事網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷(xiāo)、小程序定制開(kāi)發(fā)、網(wǎng)站運(yùn)營(yíng)為一體的建站企業(yè);在網(wǎng)站建設(shè)告別千篇一律,告別似曾相識(shí),這一次我們重新定義網(wǎng)站建設(shè),讓您的網(wǎng)站別具一格。自適應(yīng)網(wǎng)站建設(shè),實(shí)現(xiàn)全網(wǎng)營(yíng)銷(xiāo)!一站適應(yīng)多終端,一樣的建站,不一樣的體驗(yàn)!

Android應(yīng)用程序進(jìn)程在啟動(dòng)的時(shí)候, 會(huì)在進(jìn)程中加載ActivityThread類(lèi),并且執(zhí)行這個(gè)類(lèi)的main函數(shù)。

應(yīng)用程序的消息循環(huán)過(guò)程就是在這個(gè)main函數(shù)里面實(shí)現(xiàn)的。

我們來(lái)看看這個(gè)函數(shù)的實(shí)現(xiàn),它定義在frameworks/base/core/java/android/app/ActivityThread.java文件中:

[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(); ...... } }

這個(gè)函數(shù)做了兩件事情,一是在主線程中創(chuàng)建了一個(gè)ActivityThread實(shí)例,二是通過(guò)Looper類(lèi)使主線程進(jìn)入消息循環(huán)中,這里我們只關(guān)注后者。

首先看Looper.prepareMainLooper函數(shù)的實(shí)現(xiàn),這是一個(gè)靜態(tài)成員函數(shù),定義在frameworks/base/core/java/android/os/Looper.java文件中:

 [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(); } ...... }

“Android應(yīng)用程序啟動(dòng)是怎么實(shí)現(xiàn)的”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!


本文名稱(chēng):Android應(yīng)用程序啟動(dòng)是怎么實(shí)現(xiàn)的
標(biāo)題來(lái)源:http://www.dlmjj.cn/article/ggpdse.html