Android Fk: Activity的管理结构简洁总结

学习博客:
ActivityRecord、TaskRecord、ActivityStack以及Activity启动模式详解:https://www.jianshu.com/p/94816e52cd77

一.主要结构:

Android Fk: Activity的管理结构简洁总结_第1张图片
在这里插入图片描述
  1. AMS初始化构造函数时会创建一个ActivityStackSupervisor对象。
  2. 一个ActivityRecord对应一个Activity,保存了一个Activity的所有信息;但是一个Activity可能会有多个ActivityRecord,因为Activity可以被多次启动,这个主要取决于其启动模式。
  3. 一个TaskRecord由一个或者多个ActivityRecord组成,这就是我们常说的任务栈,具有后进先出的特点。
  4. ActivityStack则是用来管理TaskRecord的,包含了多个TaskRecord。
  5. ActivityDisplay中有个mStack的ActivityStack的列表,管理着在该显示界面显示的所有ActivityStack

二. Dumpsys Activity

adb shell dumpsys activity得到Activity的所有信息:

//总体可以看出是一个ActivityDisplay包含4个ActivityStack,
//每个ActivityStack中可以包含多个TaskRecord,
//每个TaskRecord中包含多个ActivityRecord
ACTIVITY MANAGER STARTER (dumpsys activity containers)
com.android.server.am.ActivityStackSupervisor@3b15212 type=undefined mode=fullscreen
  #0 ActivityDisplay={0 numStacks=4} type=undefined mode=fullscreen
   #3 ActivityStack{1309fff stackId=14 type=standard mode=fullscreen visible=true translucent=false, 1 tasks} type=standard mode=fullscreen
    #0 TaskRecord{f1ca359 #18 A=com.miui.gallery.home U=0 StackId=14 sz=1} type=standard mode=fullscreen
     #0 ActivityRecord{55efd9b u0 com.miui.gallery/.activity.HomePageActivity t18} type=standard mode=fullscreen
   #2 ActivityStack{d16beab stackId=0 type=home mode=fullscreen visible=false translucent=true, 1 tasks} type=home mode=fullscreen
    #0 TaskRecord{b0ad8fa #1 I=com.miui.home/.launcher.Launcher U=0 StackId=0 sz=1} type=home mode=fullscreen
     #0 ActivityRecord{2e8cf35 u0 com.miui.home/.launcher.Launcher t1} type=home mode=fullscreen
   #1 ActivityStack{cbe739a stackId=13 type=standard mode=fullscreen visible=false translucent=true, 1 tasks} type=standard mode=fullscreen
    #0 TaskRecord{e03a045 #17 A=com.android.camera U=0 StackId=13 sz=1} type=standard mode=fullscreen
     #0 ActivityRecord{790844e u0 com.android.camera/.Camera t17} type=standard mode=fullscreen
   #0 ActivityStack{6fc5186 stackId=15 type=recents mode=fullscreen visible=false translucent=true, 1 tasks} type=recents mode=fullscreen
    #0 TaskRecord{db1c8 #19 A=com.android.systemui U=0 StackId=15 sz=1} type=recents mode=fullscreen
     #0 ActivityRecord{e6b1c15 u0 com.android.systemui/.recents.RecentsActivity t19} type=recents mode=fullscreen

ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Display #0 (activities from top to bottom):
//ActivityStack 14
  Stack #14: type=standard mode=fullscreen
  ...
   //可以看到该栈中的TaskRecord信息
    * TaskRecord{f1ca359 #18 A=com.miui.gallery.home U=0 StackId=14 sz=1}
      userId=0 effectiveUid=u0a64 mCallingUid=u0a65 mUserSetupComplete=true mCallingPackage=com.miui.home
      affinity=com.miui.gallery.home
      intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.miui.gallery/.activity.HomePageActivity}
      realActivity=com.miui.gallery/.activity.HomePageActivity
      autoRemoveRecents=false isPersistable=true numFullscreen=1 activityType=1
      rootWasReset=true mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{55efd9b u0 com.miui.gallery/.activity.HomePageActivity t18}]
      askedCompatMode=false inRecents=true isAvailable=true
      mRootProcess=ProcessRecord{5698195 5810:com.miui.gallery/u0a64}
      stackId=14
      hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION mSupportsPictureInPicture=false isResizeable=true supportsSplitScreenWindowingMode=true lastActiveTime=9269146 (inactive for 2s)
        Hist #0: ActivityRecord{55efd9b u0 com.miui.gallery/.activity.HomePageActivity t18}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.miui.gallery/.activity.HomePageActivity bnds=[330,1077][498,1245] (has extras) }
          ProcessRecord{5698195 5810:com.miui.gallery/u0a64}

    Running activities (most recent first):
      TaskRecord{f1ca359 #18 A=com.miui.gallery.home U=0 StackId=14 sz=1}
        Run #0: ActivityRecord{55efd9b u0 com.miui.gallery/.activity.HomePageActivity t18}
    //当前显示在界面上的Activity
    mResumedActivity: ActivityRecord{55efd9b u0 com.miui.gallery/.activity.HomePageActivity t18}

//Launcher的ActivityStack
  Stack #0: type=home mode=fullscreen
  isSleeping=false
  mBounds=Rect(0, 0 - 0, 0)

    Task id #1
    mBounds=Rect(0, 0 - 0, 0)
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{b0ad8fa #1 I=com.miui.home/.launcher.Launcher U=0 StackId=0 sz=1}
    ...    
          ProcessRecord{600f8ce 2129:com.miui.home/u0a65}

    Running activities (most recent first):
      TaskRecord{b0ad8fa #1 I=com.miui.home/.launcher.Launcher U=0 StackId=0 sz=1}
        Run #0: ActivityRecord{2e8cf35 u0 com.miui.home/.launcher.Launcher t1}
// 后台还存在ActivityStack 13,运行的是相机的应用
  Stack #13: type=standard mode=fullscreen
  isSleeping=false
  mBounds=Rect(0, 0 - 0, 0)

    Task id #17
    mBounds=Rect(0, 0 - 0, 0)
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{e03a045 #17 A=com.android.camera U=0 StackId=13 sz=1}
    ...
          ProcessRecord{73ea80c 11408:com.android.camera/u0a45}

    Running activities (most recent first):
      TaskRecord{e03a045 #17 A=com.android.camera U=0 StackId=13 sz=1}
        Run #0: ActivityRecord{790844e u0 com.android.camera/.Camera t17}

  Stack #15: type=recents mode=fullscreen
  isSleeping=false
  mBounds=Rect(0, 0 - 0, 0)

    Task id #19
    mBounds=Rect(0, 0 - 0, 0)
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{db1c8 #19 A=com.android.systemui U=0 StackId=15 sz=1}
     ...
          ProcessRecord{b7692d7 1984:com.android.systemui/1000}

    Running activities (most recent first):
      TaskRecord{db1c8 #19 A=com.android.systemui U=0 StackId=15 sz=1}
        Run #0: ActivityRecord{e6b1c15 u0 com.android.systemui/.recents.RecentsActivity t19}
  //当前显示着的ActivityStack
  ResumedActivity: ActivityRecord{55efd9b u0 com.miui.gallery/.activity.HomePageActivity t18}
  //当前获取焦点或显示着的ActivityStack
  mFocusedStack=ActivityStack{1309fff stackId=14 type=standard mode=fullscreen visible=true translucent=false, 1 tasks} mLastFocusedStack=ActivityStack{1309fff stackId=14 type=standard mode=fullscreen visible=true translucent=false, 1 tasks}
  //Displayid为0的界面上有4个ActivityStack
  displayId=0 stacks=4 
   mHomeStack=ActivityStack{d16beab stackId=0 type=home mode=fullscreen visible=false translucent=true, 1 tasks}
   mRecentsStack=ActivityStack{6fc5186 stackId=15 type=recents mode=fullscreen visible=false translucent=true, 1 tasks}
...

你可能感兴趣的:(Android Fk: Activity的管理结构简洁总结)