ActivityThread and ApplicationThread

來源:互聯網
上載者:User

D:linuxlinuxkernelsrccm10.1rameworksasecorejavaandroidappActivityThread.java

/**
* This manages the execution of the main thread in an
* application process, scheduling and executing activities,
* broadcasts, and other operations on it as the activity
* manager requests.
*
* {@hide}
*/
public final class ActivityThread {

 

 

http://www.devdiv.com/forum.php?mod=viewthread&tid=38129

 

主線程中會構造這兩個類的對象。
但是他們不是線程,你看看繼承關係就可以知道ApplicationThread是binder, ActivityThread是一個final類也不是真正的線程。
如果你用ddms查看某一個進程的所有線程,你會發現它只有一個main thread,當然它可能還有binder thread, jdwp, signal catcher等。

 

一個應用程式對應一個ActivityThread執行個體,應用程式由activityThread開啟訊息迴圈, 同時,一個應用程式也對應一個ApplicationThread對象,此對象是ActivityThread 與 ActivityManagerService串連的橋樑

應該不是一個應用程式對應一個ActivityThread執行個體,而是一個進程對應一個ActivityThread執行個體,這個進程裡面所有的activity對應這一個ActivityThread執行個體,你可以看看ActivityThread類包含了mActivities。

 

 

 

Step 3. Activity.startActivityForResult

這個函數也是實現在frameworks/base/core/java/android/app/Activity.java檔案中:

[java]  
  1. public class Activity extends ContextThemeWrapper implements LayoutInflater.Factory,
  2. Window.Callback, KeyEvent.Callback, OnCreateContextMenuListener, ComponentCallbacks {
  3. ......
  4. public void startActivityForResult(Intent intent, int requestCode) {
  5. if (mParent == null) { Instrumentation.ActivityResult ar =
  6. mInstrumentation.execStartActivity( this, mMainThread.getApplicationThread(), mToken, this,
  7. intent, requestCode); ......
  8. } else { ......
  9. }
  10. ......
  11. } 這裡的mInstrumentation是Activity類的成員變數,它的類型是Intrumentation,定義在frameworks/base/core/java/android/app/Instrumentation.java檔案中,它用來監控應用程式和系統的互動。

    這裡的mMainThread也是Activity類的成員變數,它的類型是ActivityThread,它代表的是應用程式的主線程,我們在Android系統在新進程中啟動自訂服務過程(startService)的原理分析一文中已經介紹過了。這裡通過mMainThread.getApplicationThread獲得它裡面的ApplicationThread成員變數,它是一個Binder對象,後面我們會看到,ActivityManagerService會使用它來和ActivityThread來進行處理序間通訊。這裡我們需注意的是,這裡的mMainThread代表的是Launcher應用程式啟動並執行進程。

    這裡的mToken也是Activity類的成員變數,它是一個Binder對象的遠程介面。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.