Android 返回堆栈管理打印 Android 中当前运行的 Activity 任务栈信息 | Activity 任务栈信息分析 | Activity 在相同 Stack 中的不同 Task(代码片

Posted 韩曙亮

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 返回堆栈管理打印 Android 中当前运行的 Activity 任务栈信息 | Activity 任务栈信息分析 | Activity 在相同 Stack 中的不同 Task(代码片相关的知识,希望对你有一定的参考价值。





一、打印 android 中当前运行的 Activity 任务栈信息



使用如下命令 , 打印 Android 手机中的 Activity 栈 :

adb shell dumpsys activity activities

命令行输出结果 : 打开 CSDN 客户端 , 然后任意点击一篇博客进入 , 输入内容如下 ;

C:\\Users\\octop>adb shell dumpsys activity activities
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Display #0 (activities from top to bottom):

  Stack #365: type=standard mode=fullscreen
  isSleeping=false
  mBounds=Rect(0, 0 - 0, 0)
    Task id #2967
    mBounds=Rect(0, 0 - 0, 0)
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{818ac96 #2967 A=net.csdn.csdnplus U=0 StackId=365 sz=2}
      userId=0 effectiveUid=u0a589 mCallingUid=u0a589 mUserSetupComplete=true mCallingPackage=net.csdn.csdnplus
      affinity=net.csdn.csdnplus
      intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=net.csdn.csdnplus/.activity.SplashActivity}
      realActivity=net.csdn.csdnplus/.activity.SplashActivity
      autoRemoveRecents=false isPersistable=true numFullscreen=2 activityType=1
      rootWasReset=true mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{b5b0b75 u0 net.csdn.csdnplus/.activity.MainActivity t2967}, ActivityRecord{f7f215 u0 net.csdn.csdnplus/.activity.BlogDetailActivity t2967}]
      askedCompatMode=false inRecents=true isAvailable=true
      mRootProcess=ProcessRecord{acfdace 20850:net.csdn.csdnplus/u0a589}
      stackId=365
      hasBeenVisible=true mResizeMode=RESIZE_MODE_UNRESIZEABLE mSupportsPictureInPicture=false isResizeable=false lastActiveTime=1319867313 (inactive for 35s)
      * Hist #1: ActivityRecord{f7f215 u0 net.csdn.csdnplus/.activity.BlogDetailActivity t2967}
          packageName=net.csdn.csdnplus processName=net.csdn.csdnplus
          launchedFromUid=10589 launchedFromPackage=net.csdn.csdnplus userId=0
          app=ProcessRecord{acfdace 20850:net.csdn.csdnplus/u0a589}
          Intent { cmp=net.csdn.csdnplus/.activity.BlogDetailActivity (has extras) }
          frontOfTask=false task=TaskRecord{818ac96 #2967 A=net.csdn.csdnplus U=0 StackId=365 sz=2}
          taskAffinity=net.csdn.csdnplus
          realActivity=net.csdn.csdnplus/.activity.BlogDetailActivity
          baseDir=/data/app/net.csdn.csdnplus-AKxdXv4cmCAwI4i4p3DLtA==/base.apk
          dataDir=/data/user/0/net.csdn.csdnplus
          stateNotNeeded=false componentSpecified=true mActivityType=standard
          compat={420dpi} labelRes=0x7f11008e icon=0x7f0807ef theme=0x7f120023
          mLastReportedConfigurations:
           mGlobalConfig={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1794) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode=fullscreen mActivityType=undefined} s.161}
           mOverrideConfig={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1794) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode=fullscreen mActivityType=standard} s.161}
          CurrentConfiguration={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1794) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode=fullscreen mActivityType=standard} s.161}
          taskDescription: label="null" icon=null iconResource=0 iconFilename=null primaryColor=fff5f5f5
           backgroundColor=fffafafa
           statusBarColor=ff757575
           navigationBarColor=ff000000
          launchFailed=false launchCount=1 lastLaunchTime=-35s702ms
          haveState=false icicle=null
          state=RESUMED stopped=false delayedResume=false finishing=false
          keysPaused=false inHistory=true visible=true sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_NOT_SHOWN
          fullscreen=true noDisplay=false immersive=false launchMode=0
          frozenBeforeDestroy=false forceNewConfig=false
          mActivityType=standard
          waitingVisible=false nowVisible=true lastVisibleTime=-35s110ms
          resizeMode=RESIZE_MODE_UNRESIZEABLE
          mLastReportedMultiWindowMode=false mLastReportedPictureInPictureMode=false
          maxAspectRatio=2.3
      * Hist #0: ActivityRecord{b5b0b75 u0 net.csdn.csdnplus/.activity.MainActivity t2967}
          packageName=net.csdn.csdnplus processName=net.csdn.csdnplus
          launchedFromUid=10589 launchedFromPackage=net.csdn.csdnplus userId=0
          app=ProcessRecord{acfdace 20850:net.csdn.csdnplus/u0a589}
          Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=net.csdn.csdnplus/.activity.MainActivity }
          frontOfTask=true task=TaskRecord{818ac96 #2967 A=net.csdn.csdnplus U=0 StackId=365 sz=2}
          taskAffinity=net.csdn.csdnplus
          realActivity=net.csdn.csdnplus/.activity.MainActivity
          baseDir=/data/app/net.csdn.csdnplus-AKxdXv4cmCAwI4i4p3DLtA==/base.apk
          dataDir=/data/user/0/net.csdn.csdnplus
          stateNotNeeded=false componentSpecified=true mActivityType=standard
          compat={420dpi} labelRes=0x7f11008e icon=0x7f0807ef theme=0x7f12022c
          mLastReportedConfigurations:
           mGlobalConfig={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1794) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode=fullscreen mActivityType=undefined} s.161}
           mOverrideConfig={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1794) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode=fullscreen mActivityType=standard} s.161}
          CurrentConfiguration={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1794) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode=fullscreen mActivityType=standard} s.161}
          taskDescription: label="null" icon=null iconResource=0 iconFilename=null primaryColor=fff5f5f5
           backgroundColor=fffafafa
           statusBarColor=ff757575
           navigationBarColor=ff000000
          launchFailed=false launchCount=0 lastLaunchTime=-1m34s561ms
          haveState=true icicle=Bundle[mParcelledData.dataSize=25948]
          state=STOPPED stopped=true delayedResume=false finishing=false
          keysPaused=false inHistory=true visible=false sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_NOT_SHOWN
          fullscreen=true noDisplay=false immersive=false launchMode=2
          frozenBeforeDestroy=false forceNewConfig=false
          mActivityType=standard
          waitingVisible=false nowVisible=false lastVisibleTime=-1m33s467ms
          connections=[ConnectionRecord{47e823f u0 CR net.csdn.csdnplus/.module.im.socket.JWebSocketClientService:@577de5e}, ConnectionRecord{6447a37 u0 CR net.csdn.csdnplus/.module.im.socket.JWebSocketClientService:@577de5e}]
          resizeMode=RESIZE_MODE_UNRESIZEABLE
          mLastReportedMultiWindowMode=false mLastReportedPictureInPictureMode=false
          maxAspectRatio=2.3

    Running activities (most recent first):
      TaskRecord{818ac96 #2967 A=net.csdn.csdnplus U=0 StackId=365 sz=2}
        Run #1: ActivityRecord{f7f215 u0 net.csdn.csdnplus/.activity.BlogDetailActivity t2967}
        Run #0: ActivityRecord{b5b0b75 u0 net.csdn.csdnplus/.activity.MainActivity t2967}

    mResumedActivity: ActivityRecord{f7f215 u0 net.csdn.csdnplus/.activity.BlogDetailActivity t2967}
    mLastPausedActivity: ActivityRecord{b5b0b75 u0 net.csdn.csdnplus/.activity.MainActivity t2967}

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

    Task id #2605
    mBounds=Rect(0, 0 - 0, 0)
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{937f032 #2605 I=com.google.android.apps.nexuslauncher/.NexusLauncherActivity U=0 StackId=0 sz=1}
      userId=0 effectiveUid=u0a64 mCallingUid=u0a64 mUserSetupComplete=true mCallingPackage=com.google.android.apps.nexuslauncher
      intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000100 cmp=com.google.android.apps.nexuslauncher/.NexusLauncherActivity}
      realActivity=com.google.android.apps.nexuslauncher/.NexusLauncherActivity
      autoRemoveRecents=false isPersistable=true numFullscreen=1 activityType=2
      rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{958eefd u0 com.google.android.apps.nexuslauncher/.NexusLauncherActivity t2605}]
      askedCompatMode=false inRecents=true isAvailable=true
      mRootProcess=ProcessRecord{1c38859 14689:com.google.android.apps.nexuslauncher/u0a64}
      stackId=0
      hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE mSupportsPictureInPicture=false isResizeable=true lastActiveTime=1319802016 (inactive for 100s)
      * Hist #0: ActivityRecord{958eefd u0 com.google.android.apps.nexuslauncher/.NexusLauncherActivity t2605}
          packageName=com.google.android.apps.nexuslauncher processName=com.google.android.apps.nexuslauncher
          launchedFromUid=0 launchedFromPackage=null userId=0
          app=ProcessRecord{1c38859 14689:com.google.android.apps.nexuslauncher/u0a64}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000100 cmp=com.google.android.apps.nexuslauncher/.NexusLauncherActivity }
          frontOfTask=true task=TaskRecord{937f032 #2605 I=com.google.android.apps.nexuslauncher/.NexusLauncherActivity U=0 StackId=0 sz=1}
          taskAffinity=null
          realActivity=com.google.android.apps.nexuslauncher/.NexusLauncherActivity
          baseDir=/system/priv-app/NexusLauncherPrebuilt/NexusLauncherPrebuilt.apk
          dataDir=/data/user/0/com.google.android.apps.nexuslauncher
          stateNotNeeded=true componentSpecified=false mActivityType=home
          compat={420dpi} labelRes=0x7f110030 icon=0x7f080039 theme=0x7f120002
          mLastReportedConfigurations:
           mGlobalConfig={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1794, 1080) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode=fullscreen mActivityType=undefined} s.159}
           mOverrideConfig={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1794) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode=fullscreen mActivityType=home} s.159}
          CurrentConfiguration={1.0 460mcc1mnc [zh_CN,en_US,zh_HK_#Hant,ja_JP,ru_BY,ar_JO,ko_KR,ar_XB] ldltr sw411dp w411dp h659dp 420dpi nrml hdr widecg port finger -keyb/v/h -nav/h winConfig={ mBounds=Rect(0, 0 - 1080, 1794) mAppBounds=Rect(0, 0 - 1080, 1794) mWindowingMode在日志中打印当前返回堆栈

手机调试Android程序出异常时不打印堆栈信息

Android系统源码或内核中打印函数调用堆栈(打印堆栈)

Android系统源码或内核中打印函数调用堆栈(打印堆栈)

Android系统源码或内核中打印函数调用堆栈(打印堆栈)

Android下打印调试堆栈方法(转)