adb shell dumpsys activity activities调用信息分析

执行命令

adb shell dumpsys activity activities 包名

在实际开发过程中,需要经常查看activity的调用栈信息,经常用到adb shell dumpsys activity activities这个命令,下面对这个命令做一下简要分析:

通过执行上面命令,可以得到类似如下格式的信息:

Stack #45: type=standard mode=fullscreen
isSleeping=false
mBounds=Rect(0, 0 - 0, 0)
......
Stack #0: type=home mode=fullscreen
isSleeping=false
mBounds=Rect(0, 0 - 0, 0)
......
Stack #1: type=recents mode=fullscreen
isSleeping=false
mBounds=Rect(0, 0 - 0, 0)
......

其中每个Stack开始代表一个App的活动栈,每个活动栈有一个id,如上所示的Stack #45中的45。

android系统中目前定义了两种类型的Stack,系统预定义的静态栈,总共有五种,如下所示:

  1. HOME_STACK_ID:Home应用以及recents app所在的栈

  2. FULLSCREEN_WORKSPACE_STACK_ID:一般应用所在的栈

  3. FREEFORM_WORKSPACE_STACK_ID:类似桌面操作系统

  4. DOCKED_STACK_ID:分屏

  5. PINNED_STACK_ID:画中画栈

另一种栈,是系统动态生成的,它的id就是大于4

Stack信息分析
我们抽取dump出的一个stack进行分析:

Stack #4: type=standard mode=fullscreen     //Stack信息
isSleeping=false
mBounds=Rect(0, 0 - 0, 0)
Task id #51              //Task信息
mBounds=Rect(0, 0 - 0, 0)
mMinWidth=-1
mMinHeight=-1
mLastNonFullscreenBounds=null
* TaskRecord{e0bdfdf #51 A=android.tplink.sjj.teststack U=0 StackId=4 sz=2}
  userId=0 effectiveUid=u0a128 mCallingUid=u0a28 mUserSetupComplete=true mCallingPackage=com.cyanogenmod.trebuchet
  affinity=android.tplink.sjj.teststack
  intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=android.tplink.sjj.teststack/.MainActivity}   //启动信息,包括启动源和被启动app的MainActivity
  realActivity=android.tplink.sjj.teststack/.MainActivity
  autoRemoveRecents=false isPersistable=true numFullscreen=2 activityType=1
  rootWasReset=true mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
  **Activities=[ActivityRecord{4542de6 u0 android.tplink.sjj.teststack/.MainActivity t51}, ActivityRecord{898d92a u0 android.tplink.sjj.teststack/.FirstActivity t51}]**   //当前栈中Activity记录
  askedCompatMode=false inRecents=true isAvailable=true
  mRootProcess=ProcessRecord{ebe742c 31812:android.tplink.sjj.teststack/u0a128}
  stackId=4
  hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION mSupportsPictureInPicture=false isResizeable=true lastActiveTime=256734507 (inactive for 30s)
  * Hist #1: ActivityRecord{898d92a u0 android.tplink.sjj.teststack/.FirstActivity t51}   //栈中Activity调用历史(最近的)
      packageName=android.tplink.sjj.teststack processName=android.tplink.sjj.teststack
      launchedFromUid=10128 launchedFromPackage=android.tplink.sjj.teststack userId=0
      app=ProcessRecord{ebe742c 31812:android.tplink.sjj.teststack/u0a128}
      Intent { flg=0x10000000 cmp=android.tplink.sjj.teststack/.FirstActivity }
      frontOfTask=false task=TaskRecord{e0bdfdf #51 A=android.tplink.sjj.teststack U=0 StackId=4 sz=2}
      taskAffinity=android.tplink.sjj.teststack
      realActivity=android.tplink.sjj.teststack/.FirstActivity
      baseDir=/data/app/android.tplink.sjj.teststack-Cu_ETALVG7u-Plh9vUC5Ug==/base.apk
      dataDir=/data/user/0/android.tplink.sjj.teststack
      splitDir=[/data/app/android.tplink.sjj.teststack-Cu_ETALVG7u-Plh9vUC5Ug==/split_lib_dependencies_apk.apk, 
      .........................................
      fullscreen=true noDisplay=false immersive=false launchMode=2
      frozenBeforeDestroy=false forceNewConfig=false
      mActivityType=standard
      waitingVisible=false nowVisible=true lastVisibleTime=-33s65ms
      resizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
      mLastReportedMultiWindowMode=false mLastReportedPictureInPictureMode=false
  * Hist #0: ActivityRecord{4542de6 u0 android.tplink.sjj.teststack/.MainActivity t51}   //同上,这是在上个历史之前的
      packageName=android.tplink.sjj.teststack processName=android.tplink.sjj.teststack
      launchedFromUid=10028 launchedFromPackage=com.cyanogenmod.trebuchet userId=0
      app=ProcessRecord{ebe742c 31812:android.tplink.sjj.teststack/u0a128}
      Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=android.tplink.sjj.teststack/.MainActivity bnds=[24,204][192,398] }
      frontOfTask=true task=TaskRecord{e0bdfdf #51 A=android.tplink.sjj.teststack U=0 StackId=4 sz=2}
      taskAffinity=android.tplink.sjj.teststack
      realActivity=android.tplink.sjj.teststack/.MainActivity
      baseDir=/data/app/android.tplink.sjj.teststack-Cu_ETALVG7u-Plh9vUC5Ug==/base.apk
      dataDir=/data/user/0/android.tplink.sjj.teststack
      splitDir=[/data/app/android.tplink.sjj.teststack-Cu_ETALVG7u-Plh9vUC5Ug==/split_lib_dependencies_apk.apk, 
      fullscreen=true noDisplay=false immersive=false launchMode=0
      frozenBeforeDestroy=false forceNewConfig=false
      mActivityType=standard
      waitingVisible=false nowVisible=false lastVisibleTime=-36s658ms
      resizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION
      mLastReportedMultiWindowMode=false mLastReportedPictureInPictureMode=false
      .......................................
      
Running activities (most recent first):  //最近该任务栈中活动了的Activity,按最近时间排列
  TaskRecord{e0bdfdf #51 A=android.tplink.sjj.teststack U=0 StackId=4 sz=2}
    Run #1: ActivityRecord{898d92a u0 android.tplink.sjj.teststack/.FirstActivity t51}
    Run #0: ActivityRecord{4542de6 u0 android.tplink.sjj.teststack/.MainActivity t51}

mResumedActivity: ActivityRecord{898d92a u0 android.tplink.sjj.teststack/.FirstActivity t51}   //当前页面Activity
mLastPausedActivity: ActivityRecord{4542de6 u0 android.tplink.sjj.teststack/.MainActivity t51}  //最后一个退出前台的Activity
..........................

转自:https://blog.csdn.net/zhang_jun_xiang/article/details/97002514

posted @ 2021-03-10 22:18  似水流云  阅读(2603)  评论(0编辑  收藏  举报