日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Android應(yīng)用程序消息處理機(jī)制(Looper、Handler)分析(10)

應(yīng)用程序的主線程準(zhǔn)備就好消息隊(duì)列并且進(jìn)入到消息循環(huán)后,其它地方就可以往這個(gè)消息隊(duì)列中發(fā)送消息了。

我們繼續(xù)以文章開始介紹的Android應(yīng)用程序啟動(dòng)過程源代碼分析一文中的應(yīng)用程序啟動(dòng)過為例,說明應(yīng)用程序是如何把消息加入到應(yīng)用程序的消息隊(duì)列中去的。

在Android應(yīng)用程序啟動(dòng)過程源代碼分析這篇文章的Step 30中,ActivityManagerService通過調(diào)用ApplicationThread類的scheduleLaunchActivity函 數(shù)通知應(yīng)用程序。

它可以加載應(yīng)用程序的默認(rèn)Activity了,這個(gè)函數(shù)定義在frameworks/base/core/java/android /app/ActivityThread.java文件中:

 
 
  1.   [java] view plaincopypublic final class ActivityThread { 
  2.   ...... 
  3.   private final class ApplicationThread extends ApplicationThreadNative { 
  4.   ...... 
  5.   // we use token to identify this activity without having to send the 
  6.   // activity itself back to the activity manager. (matters more with 
  7. ipc) 
  8.   public final void scheduleLaunchActivity(Intent intent, IBinder token, int 
  9. ident, 
  10.   ActivityInfo info, Bundle state, List pendingResults, 
  11.   List pendingNewIntents, boolean notResumed, boolean isForward) 
  12.   ActivityClientRecord r = new ActivityClientRecord(); 
  13.   r.token = token; 
  14.   r.ident = ident; 
  15.   r.intent = intent; 
  16.   r.activityInfo = info; 
  17.   r.state = state; 
  18.   r.pendingResults = pendingResults; 
  19.   r.pendingIntents = pendingNewIntents; 
  20.   r.startsNotResumed = notResumed; 
  21.   r.isForward = isForward; 
  22.   queueOrSendMessage(H.LAUNCH_ACTIVITY, r); 
  23.   } 
  24.   ...... 
  25.   } 
  26.   ...... 
  27.   } 

這里把相關(guān)的參數(shù)都封裝成一個(gè)ActivityClientRecord對(duì)象r,然后調(diào)用queueOrSendMessage函數(shù)來往應(yīng)用程序的消息隊(duì) 列中加入一個(gè)新的消息(H.LAUNCH_ACTIVITY),這個(gè)函數(shù)定義在frameworks/base/core/java/android /app/ActivityThread.java文件中:

 
 
  1. [java] view plaincopypublic final class ActivityThread { 
  2. ...... 
  3. private final class ApplicationThread extends ApplicationThreadNative { 
  4. ...... 
  5. // if the thread hasn't started yet, we don't have the handler, so just 
  6. // save the messages until we're ready. 
  7. private final void queueOrSendMessage(int what, Object obj) { 
  8. queueOrSendMessage(what, obj, 0, 0); 
  9. ...... 
  10. private final void queueOrSendMessage(int what, Object obj, int arg1, int 
  11. g2) { 
  12. synchronized (this) { 
  13. ...... 
  14. Message msg = Message.obtain(); 
  15. msg.what = what; 
  16. msg.obj = obj; 
  17. msg.arg1 = arg1; 
  18. msg.arg2 = arg2; 
  19. mH.sendMessage(msg); 
  20. ...... 
  21. ...... 

本文題目:Android應(yīng)用程序消息處理機(jī)制(Looper、Handler)分析(10)
網(wǎng)站地址:http://www.5511xx.com/article/cccgego.html