简述

在 App 开发调试过程中,可能需要查看 App 的 Activity 栈用于校验 Activity 的跳转情况是否正确
查看 Activity 栈的操作步骤:

  • 连接真机/模拟器
  • adb shell进入 Android 系统
  • dumpsys activity activities查看 Activity 栈信息
    • 命令会输出所有正在运行中的 App 堆栈信息,查看之前需要关闭其他无关 App,否则输出信息太多

adb - 查看 Activity 栈 - 图1

示例信息

  1. // - adb shell 进入 Android 系统
  2. // 查看 Activity 栈信息
  3. HWVTR:/ $ dumpsys activity activities
  4. ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
  5. Display #0 (activities from top to bottom):
  6. // 栈顶进程
  7. Stack #276: type=standard mode=fullscreen
  8. isSleeping=false
  9. mBounds=Rect(0, 0 - 0, 0)
  10. Task id #1922
  11. mBounds=Rect(0, 0 - 0, 0)
  12. mMinWidth=-1
  13. mMinHeight=-1
  14. mLastNonFullscreenBounds=null
  15. * TaskRecord{515d010 #1922 A=11146:com.emao.taochemao U=0 StackId=276 sz=1}
  16. userId=0 effectiveUid=u0a1146 mCallingUid=u0a63 mUserSetupComplete=true mCallingPackage=com.huawei.android.launcher
  17. affinity=11146:com.emao.taochemao
  18. intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.emao.taochemao/.activity.TestActivity}
  19. realActivity=com.emao.taochemao/.activity.TestActivity
  20. autoRemoveRecents=false isPersistable=true numFullscreen=1 activityType=1
  21. rootWasReset=true mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
  22. Activities=[ActivityRecord{34ac0dc u0 com.emao.taochemao/.activity.TestActivity t1922}]
  23. askedCompatMode=false inRecents=true isAvailable=true
  24. mRootProcess=ProcessRecord{f556f62 1340:com.emao.taochemao/u0a1146}
  25. stackId=276
  26. hasBeenVisible=false mResizeMode=RESIZE_MODE_UNRESIZEABLE mSupportsPictureInPicture=false isResizeable=false lastActiveTime=544638619 (inactive for 2s)
  27. // 进程内 Activity 栈详情信息
  28. * Hist #0: ActivityRecord{34ac0dc u0 com.emao.taochemao/.activity.TestActivity t1922}
  29. packageName=com.emao.taochemao processName=com.emao.taochemao
  30. launchedFromUid=10063 launchedFromPackage=com.huawei.android.launcher userId=0
  31. app=ProcessRecord{f556f62 1340:com.emao.taochemao/u0a1146}
  32. Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.emao.taochemao/.activity.TestActivity bnds=[435,654][645,939] }
  33. frontOfTask=true task=TaskRecord{515d010 #1922 A=11146:com.emao.taochemao U=0 StackId=276 sz=1}
  34. taskAffinity=11146:com.emao.taochemao
  35. realActivity=com.emao.taochemao/.activity.TestActivity
  36. baseDir=/data/app/com.emao.taochemao-rOZiJbPodHnjB3hWsT3u1w==/base.apk
  37. dataDir=/data/user/0/com.emao.taochemao
  38. stateNotNeeded=false componentSpecified=true mActivityType=standard
  39. compat={480dpi} labelRes=0x7f100042 icon=0x7f0d0000 theme=0x7f1100ca
  40. mLastReportedConfigurations:
  41. mGlobalConfig={1.0 ?mcc?mnc [zh_CN_#Hans] ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 0, 0) mAppBounds=Rect(0, 0 - 1080, 1920) mWindowingMode=fullscreen mActivityType=undefined} nonFullScreen=0 suim:1 s.6}
  42. mOverrideConfig={1.0 ?mcc?mnc [zh_CN_#Hans] ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1920) mAppBounds=Rect(0, 0 - 1080, 1920) mWindowingMode=fullscreen mActivityType=standard} nonFullScreen=0 suim:1 s.6}
  43. CurrentConfiguration={1.0 ?mcc?mnc [zh_CN_#Hans] ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1920) mAppBounds=Rect(0, 0 - 1080, 1920) mWindowingMode=fullscreen mActivityType=standard} nonFullScreen=0 suim:1 s.6}
  44. launchFailed=false launchCount=1 lastLaunchTime=-2s797ms
  45. haveState=true icicle=null
  46. state=RESUMED stopped=false delayedResume=false finishing=false
  47. keysPaused=false inHistory=true visible=true sleeping=false idle=false mStartingWindowState=STARTING_WINDOW_SHOWN
  48. fullscreen=true noDisplay=false immersive=false launchMode=0
  49. frozenBeforeDestroy=false forceNewConfig=false
  50. mActivityType=standard
  51. displayStartTime=-2s799ms startTime=0
  52. resizeMode=RESIZE_MODE_UNRESIZEABLE
  53. mLastReportedMultiWindowMode=false mLastReportedPictureInPictureMode=false
  54. maxAspectRatio=2.4
  55. // 进程内 Activity 栈简略信息
  56. Running activities (most recent first):
  57. TaskRecord{515d010 #1922 A=11146:com.emao.taochemao U=0 StackId=276 sz=1}
  58. Run #0: ActivityRecord{34ac0dc u0 com.emao.taochemao/.activity.TestActivity t1922}
  59. mResumedActivity: ActivityRecord{34ac0dc u0 com.emao.taochemao/.activity.TestActivity t1922}
  60. // 栈内第 2 进程
  61. Stack #0: type=home mode=fullscreen
  62. isSleeping=false
  63. mBounds=Rect(0, 0 - 0, 0)
  64. Task id #1
  65. mBounds=Rect(0, 0 - 0, 0)
  66. mMinWidth=-1
  67. mMinHeight=-1
  68. mLastNonFullscreenBounds=null
  69. * TaskRecord{1a1e1d4 #1 A=10063:com.huawei.android.launcher U=0 StackId=0 sz=1}
  70. userId=0 effectiveUid=u0a63 mCallingUid=1000 mUserSetupComplete=true mCallingPackage=android
  71. affinity=10063:com.huawei.android.launcher
  72. intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000300 cmp=com.huawei.android.launcher/.unihome.UniHomeLauncher}
  73. realActivity=com.huawei.android.launcher/.unihome.UniHomeLauncher
  74. autoRemoveRecents=false isPersistable=true numFullscreen=1 activityType=2
  75. rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
  76. Activities=[ActivityRecord{2ec4195 u0 com.huawei.android.launcher/.unihome.UniHomeLauncher t1}]
  77. askedCompatMode=false inRecents=true isAvailable=true
  78. mRootProcess=ProcessRecord{df8f238 2321:com.huawei.android.launcher/u0a63}
  79. stackId=0
  80. hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE mSupportsPictureInPicture=false isResizeable=true lastActiveTime=544638494 (inactive for 2s)
  81. * Hist #0: ActivityRecord{2ec4195 u0 com.huawei.android.launcher/.unihome.UniHomeLauncher t1}
  82. packageName=com.huawei.android.launcher processName=com.huawei.android.launcher
  83. launchedFromUid=0 launchedFromPackage=null userId=0
  84. app=ProcessRecord{df8f238 2321:com.huawei.android.launcher/u0a63}
  85. Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000300 cmp=com.huawei.android.launcher/.unihome.UniHomeLauncher }
  86. frontOfTask=true task=TaskRecord{1a1e1d4 #1 A=10063:com.huawei.android.launcher U=0 StackId=0 sz=1}
  87. taskAffinity=10063:com.huawei.android.launcher
  88. realActivity=com.huawei.android.launcher/.unihome.UniHomeLauncher
  89. baseDir=/system/app/HwLauncher6/HwLauncher6.apk
  90. dataDir=/data/user_de/0/com.huawei.android.launcher
  91. stateNotNeeded=true componentSpecified=false mActivityType=home
  92. compat={480dpi} labelRes=0x7f0a00b4 icon=0x7f020223 theme=0x2060013
  93. mLastReportedConfigurations:
  94. mGlobalConfig={1.0 ?mcc?mnc [zh_CN_#Hans] ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 0, 0) mAppBounds=Rect(0, 0 - 1080, 1920) mWindowingMode=fullscreen mActivityType=undefined} nonFullScreen=0 suim:1 s.6}
  95. mOverrideConfig={1.0 ?mcc?mnc [zh_CN_#Hans] ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1920) mAppBounds=Rect(0, 0 - 1080, 1920) mWindowingMode=fullscreen mActivityType=home} nonFullScreen=0 suim:1 s.6}
  96. CurrentConfiguration={1.0 ?mcc?mnc [zh_CN_#Hans] ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1920) mAppBounds=Rect(0, 0 - 1080, 1920) mWindowingMode=fullscreen mActivityType=home} nonFullScreen=0 suim:1 s.6}
  97. OverrideConfiguration={0.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?ldr ?wideColorGamut ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/? winConfig={ mBounds=Rect(0, 0 - 0, 0) mAppBounds=null mWindowingMode=undefined mActivityType=home} nonFullScreen=0}
  98. launchFailed=false launchCount=0 lastLaunchTime=-5d7h34m48s577ms
  99. haveState=false icicle=null
  100. state=PAUSED stopped=false delayedResume=false finishing=false
  101. keysPaused=false inHistory=true visible=false sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_NOT_SHOWN
  102. fullscreen=true noDisplay=false immersive=false launchMode=2
  103. frozenBeforeDestroy=false forceNewConfig=false
  104. mActivityType=home
  105. waitingVisible=true nowVisible=false lastVisibleTime=-8s783ms
  106. connections=[ConnectionRecord{584bc23 u0 CR IMP WACT DEAD com.huawei.search/.services.overlay.LauncherOverlayService:@1d50152}, ConnectionRecord{fa5f9d2 u0 CR IMP WACT com.huawei.recsys/com.huawei.common.service.Decision:@a08fc5d}, ConnectionRecord{921f076 u0 CR IMP WACT com.huawei.search/.services.overlay.LauncherOverlayService:@1d50152}]
  107. resizeMode=RESIZE_MODE_RESIZEABLE
  108. mLastReportedMultiWindowMode=false mLastReportedPictureInPictureMode=false
  109. Running activities (most recent first):
  110. TaskRecord{1a1e1d4 #1 A=10063:com.huawei.android.launcher U=0 StackId=0 sz=1}
  111. Run #0: ActivityRecord{2ec4195 u0 com.huawei.android.launcher/.unihome.UniHomeLauncher t1}
  112. mLastPausedActivity: ActivityRecord{2ec4195 u0 com.huawei.android.launcher/.unihome.UniHomeLauncher t1}
  113. Activities waiting to stop:
  114. TaskRecord{1a1e1d4 #1 A=10063:com.huawei.android.launcher U=0 StackId=0 sz=1}
  115. Stop #0: ActivityRecord{2ec4195 u0 com.huawei.android.launcher/.unihome.UniHomeLauncher t1}
  116. Activities waiting for another to become visible:
  117. TaskRecord{1a1e1d4 #1 A=10063:com.huawei.android.launcher U=0 StackId=0 sz=1}
  118. Wait #0: ActivityRecord{2ec4195 u0 com.huawei.android.launcher/.unihome.UniHomeLauncher t1}
  119. ResumedActivity: ActivityRecord{34ac0dc u0 com.emao.taochemao/.activity.TestActivity t1922}
  120. mFocusedStack=ActivityStack{c0ea709 stackId=276 type=standard mode=fullscreen visible=true translucent=false, 1 tasks} mLastFocusedStack=ActivityStack{c0ea709 stackId=276 type=standard mode=fullscreen visible=true translucent=false, 1 tasks}
  121. mCurTaskIdForUser={0=1922}
  122. mUserStackInFront={}
  123. displayId=0 stacks=2
  124. mHomeStack=ActivityStack{ab3c2ef stackId=0 type=home mode=fullscreen visible=false translucent=true, 1 tasks}
  125. isHomeRecentsComponent=true KeyguardController:
  126. mKeyguardShowing=false
  127. mAodShowing=false
  128. mKeyguardGoingAway=false
  129. mOccluded=false
  130. mDismissingKeyguardActivity=null
  131. mDismissalRequested=false
  132. mVisibilityTransactionDepth=0
  133. LockTaskController
  134. mLockTaskModeState=NONE
  135. mLockTaskModeTasks=
  136. mLockTaskPackages (userId:packages)=
  137. u0:[]