欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android查看任务栈

程序员文章站 2022-06-08 18:00:34
...

Thanks

我是从这个博客学习到的:
http://blog.sina.com.cn/s/blog_5de73d0b0102xky0.html

本文基于此博客进行一个划重点的记录。

明确问题:
即,我们如何去观察一个app进程的Activity任务栈情况。

我为什么选择这种方式:
网上还找到一种方式,就是在terminal内直接输出相关信息,但我发现这些信息又臭又长,不能很好的观察,并且也无法copy完全到其他地方观察,这种方式比较符合我的使用习惯,感觉可靠一些。

PS:
本文的重点在于,“如何查看任务栈”,所以对于后面使用Activity启动模式作为例子并没有对启动模式深挖。
若想更深层次的了解启动模式请看这篇博客:

先给出答案

C:\Users\Administrator\Desktop>adb shell dumpsys activity -p com.packagename.packagename > taskinfos.txt

划重点:

  • dumpsys
    adb shell 核心指令,用于查看手机的运行数据。

  • -p com.packagename.packagename
    -p 后面跟的是需要观察的进程包名,你要看哪个app相关的任务栈,就跟哪一个包名。前提是你要知道该app包名。

  • C:\Users\Administrator\Desktop> … taskinfos.txt
    这个是命令输入的路径,这里是写在桌面,为什么?因为方便看,你也可以自定义路径。

验证

记不住的东西是因为你不够坚信,眼见为实,这里来个例子,我就随便打开个以前的Demo来验证。

项目基本情况

Android查看任务栈
Android查看任务栈

观察栈内情况

这里我简单验证3种情况:

  • 俩个标准启动模式的Activity,在栈内的情况
  • 2个singleTask启动模式的Activity,在栈内的情况
  • 2个singleInstance启动模式的Activity,在栈内的情况

界面就一个按钮点跳转。我这里点击了按钮,前台Activity是OtherActivity
Android查看任务栈
因为是打开的之前的demo,所以其他功能请无视,就关注这个跳转的button就行了。

俩个标准启动模式的Activity,在栈内的情况


    ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
    Display #0 (activities from top to bottom):
      Stack #1:
      mResumedActivity=ActivityRecord{edcc0b8 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1918}
      mFullscreen=true
      mBounds=null
        Task id #1918
        mFullscreen=true
        mBounds=null
        mMinWidth=-1
        mMinHeight=-1
        mLastNonFullscreenBounds=null
          TaskRecord{ab827fc #1918 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=2}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.MainActivity }
            Hist #1: ActivityRecord{edcc0b8 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1918}
              Intent { cmp=demo.greendaotest.com.greendaotestdemo/.OtherAcitivty }
              ProcessRecord{57ffe85 15943:demo.greendaotest.com.greendaotestdemo/u0a212}
              Local Activity bd7ee28 State:
                mResumed=true mStopped=false mFinished=false
                mChangingConfigurations=false
                mCurrentConfig={1.0 460mcc1mnc [zh_CN] ldltr sw360dp w360dp h620dp 480dpi nrml long port finger -keyb/v/h -nav/h s.8 themeChanged=0 themeChangedFlags=0}
                mLoadersStarted=true
                FragmentManager misc state:
                  aaa@qq.com
                  aaa@qq.com
                  mCurState=5 mStateSaved=false mDestroyed=false
              ViewRoot:
                mAdded=true mRemoved=false
                mConsumeBatchedInputScheduled=false
                mConsumeBatchedInputImmediatelyScheduled=false
                mPendingInputEventCount=0
                mProcessInputEventsScheduled=false
                mTraversalScheduled=false            mIsAmbientMode=false
                android.view.ViewRootImpl$NativePreImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$ImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$NativePostImeInputStage: mQueueLength=0
              Choreographer:
                mFrameScheduled=false
                mLastFrameTime=31805298 (261 ms ago)
              View Hierarchy:
                aaa@qq.com[OtherAcitivty]
                  android.widget.LinearLayout{be1e63b V.E...... ........ 0,0-1080,1920}
                    android.view.ViewStub{ff73158 G.E...... ......I. 0,0-0,0 #1020400 android:id/action_mode_bar_stub}
                    android.widget.FrameLayout{f5902b1 V.E...... ........ 0,60-1080,1920}
                      android.support.v7.widget.ActionBarOverlayLayout{d9e4396 V.E...... ........ 0,0-1080,1860 #7f0b004d app:id/decor_content_parent}
                        android.support.v7.widget.ContentFrameLayout{feab17 V.E...... ........ 0,168-1080,1860 #1020002 android:id/content}
                          android.support.constraint.ConstraintLayout{f5a0b04 V.E...... ........ 0,0-1080,1692}
                        android.support.v7.widget.ActionBarContainer{1ca18ed V.ED..... ........ 0,0-1080,168 #7f0b004e app:id/action_bar_container}
                          android.support.v7.widget.Toolbar{af30322 V.E...... ........ 0,0-1080,168 #7f0b004f app:id/action_bar}
                            android.support.v7.widget.AppCompatTextView{2b8e1b3 V.ED..... ........ 48,43-585,124}
                            android.support.v7.widget.ActionMenuView{eed370 V.E...... ......ID 1080,0-1080,168}
                          android.support.v7.widget.ActionBarContextView{2bc56e9 G.E...... ......I. 0,0-0,0 #7f0b0050 app:id/action_context_bar}
                  android.view.View{de22f6e V.ED..... ........ 0,0-1080,60 #102002f android:id/statusBarBackground}
              Looper (main, tid 1) {d5e60f}
                package demo.greendaotest.com.greendaotestdemo version Code: 1 version Name: 1.0 cur loop is : Looper (main, tid 1) {d5e60f}
    ---------- Dump MessageQueue on Looper (main, tid 1) {d5e60f}----------
               (Total messages: 0, polling=false, quitting=false)
    -------------------------- END --------------------------

              Local FragmentActivity bd7ee28 State:
                mCreated=truemResumed=true mStopped=false mReallyStopped=false
                mLoadersStarted=true
              FragmentManager misc state:
                aaa@qq.com69c
                maaa@qq.com5c5b69c
                mCurState=5 mStateSaved=false mDestroyed=false

            Hist #0: ActivityRecord{c25995b u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1918}
              Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.MainActivity }
              ProcessRecord{57ffe85 15943:demo.greendaotest.com.greendaotestdemo/u0a212}
              Local Activity beb66bb State:
                mResumed=false mStopped=true mFinished=false
                mChangingConfigurations=false
                mCurrentConfig={1.0 460mcc1mnc [zh_CN] ldltr sw360dp w360dp h620dp 480dpi nrml long port finger -keyb/v/h -nav/h s.8 themeChanged=0 themeChangedFlags=0}
                mLoadersStarted=true
                FragmentManager misc state:
                  aaa@qq.com
                  aaa@qq.com
                  mCurState=3 mStateSaved=true mDestroyed=false
              ViewRoot:
                mAdded=true mRemoved=false
                mConsumeBatchedInputScheduled=false
                mConsumeBatchedInputImmediatelyScheduled=false
                mPendingInputEventCount=0
                mProcessInputEventsScheduled=false
                mTraversalScheduled=false            mIsAmbientMode=false
                android.view.ViewRootImpl$NativePreImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$ImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$NativePostImeInputStage: mQueueLength=0
              Choreographer:
                mFrameScheduled=false
                mLastFrameTime=31805298 (281 ms ago)
              View Hierarchy:
                aaa@qq.com[MainActivity]
                  android.widget.LinearLayout{814d42b V.E...... .......D 0,0-1080,1920}
                    android.view.ViewStub{dc5a088 G.E...... ......I. 0,0-0,0 #1020400 android:id/action_mode_bar_stub}
                    android.widget.FrameLayout{53efa21 V.E...... .......D 0,60-1080,1920}
                      android.support.v7.widget.ActionBarOverlayLayout{28cbe46 V.E...... .......D 0,0-1080,1860 #7f0b004d app:id/decor_content_parent}
                        android.support.v7.widget.ContentFrameLayout{80a8807 V.E...... .......D 0,168-1080,1860 #1020002 android:id/content}
                          android.widget.LinearLayout{e583d34 V.E...... .......D 0,0-1080,1692}
                            android.support.v7.widget.AppCompatButton{870175d VFED..C.. ......ID 0,0-515,144 #7f0b005e app:id/jump2other}
                            android.widget.LinearLayout{dc678d2 V.E...... .......D 0,144-1080,288}
                              android.support.v7.widget.AppCompatButton{abd9da3 VFED..C.. ......ID 12,0-276,144 #7f0b001b app:id/add}
                              android.support.v7.widget.AppCompatButton{7d5f8a0 VFED..C.. ......ID 276,0-540,144 #7f0b005f app:id/del}
                              android.support.v7.widget.AppCompatButton{39bcc59 VFED..C.. ......ID 540,0-804,144 #7f0b0060 app:id/edit}
                              android.support.v7.widget.AppCompatButton{76f501e VFED..C.. ......ID 804,0-1068,144 #7f0b0061 app:id/query}
                            android.widget.ScrollView{a0270ff VFED.V... ........ 0,288-1080,1692}
                              android.widget.RelativeLayout{5b1fecc V.E...... ........ 0,0-1080,449}
                                android.support.v7.widget.AppCompatTextView{633d515 V.ED..... ........ 235,0-845,449 #7f0b0062 app:id/content_tv}
                            android.support.v7.widget.AppCompatButton{23c502a VFED..C.. ......ID 0,1692-557,1692}
                        android.support.v7.widget.ActionBarContainer{e971e1b V.ED..... ......ID 0,0-1080,168 #7f0b004e app:id/action_bar_container}
                          android.support.v7.widget.Toolbar{5663bb8 V.E...... ........ 0,0-1080,168 #7f0b004f app:id/action_bar}
                            android.support.v7.widget.AppCompatTextView{b09ad91 V.ED..... ........ 48,43-585,124}
                            android.support.v7.widget.ActionMenuView{52744f6 V.E...... ......ID 1080,0-1080,168}
                          android.support.v7.widget.ActionBarContextView{4ff80f7 G.E...... ......I. 0,0-0,0 #7f0b0050 app:id/action_context_bar}
                  android.view.View{1f5b64 V.ED..... ......ID 0,0-1080,60 #102002f android:id/statusBarBackground}
              Looper (main, tid 1) {d5e60f}
                package demo.greendaotest.com.greendaotestdemo version Code: 1 version Name: 1.0 cur loop is : Looper (main, tid 1) {d5e60f}
    ---------- Dump MessageQueue on Looper (main, tid 1) {d5e60f}----------
               (Total messages: 0, polling=false, quitting=false)
    -------------------------- END --------------------------

              Local FragmentActivity beb66bb State:
                mCreated=truemResumed=false mStopped=true mReallyStopped=true
                mLoadersStarted=true
              FragmentManager misc state:
                aaa@qq.com1cd
                maaa@qq.come8a91cd
                mCurState=2 mStateSaved=true mDestroyed=false

        Running activities (most recent first):
          TaskRecord{ab827fc #1918 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=2}
            Run #3: ActivityRecord{edcc0b8 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1918}
            Run #2: ActivityRecord{c25995b u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1918}

        mResumedActivity: ActivityRecord{edcc0b8 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1918}

      mFocusedActivity: ActivityRecord{edcc0b8 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1918}

这个东西这么多,具体怎么看呢?(搜索Hist关键字)

  • Hist #1: ActivityRecord{edcc0b8 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1918}
  • Hist #0: ActivityRecord{c25995b u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1918}

这就是当前任务栈的情况。

2个singleTask启动模式的Activity,在栈内的情况

接下来我们将俩个Activity设置为singleTask。并将OtherActivity切换至前台。
Android查看任务栈




    ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
    Display #0 (activities from top to bottom):
      Stack #1:
      mResumedActivity=ActivityRecord{59f7102 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1946}
      mFullscreen=true
      mBounds=null
        Task id #1946
        mFullscreen=true
        mBounds=null
        mMinWidth=-1
        mMinHeight=-1
        mLastNonFullscreenBounds=null
          TaskRecord{48d14ff #1946 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=2}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.MainActivity }
            Hist #1: ActivityRecord{59f7102 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1946}
              Intent { flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.OtherAcitivty }
              ProcessRecord{8b1d2cc 13475:demo.greendaotest.com.greendaotestdemo/u0a212}
              Local Activity 31cea27 State:
                mResumed=true mStopped=false mFinished=false
                mChangingConfigurations=false
                mCurrentConfig={1.0 460mcc1mnc [zh_CN] ldltr sw360dp w360dp h620dp 480dpi nrml long port finger -keyb/v/h -nav/h s.8 themeChanged=0 themeChangedFlags=0}
                mLoadersStarted=true
                FragmentManager misc state:
                  mHost=android.app.Activity$HostCallbacks@ff73158
                  mContainer=android.app.Activity$HostCallbacks@ff73158
                  mCurState=5 mStateSaved=false mDestroyed=false
              ViewRoot:
                mAdded=true mRemoved=false
                mConsumeBatchedInputScheduled=false
                mConsumeBatchedInputImmediatelyScheduled=false
                mPendingInputEventCount=0
                mProcessInputEventsScheduled=false
                mTraversalScheduled=false            mIsAmbientMode=false
                android.view.ViewRootImpl$NativePreImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$ImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$NativePostImeInputStage: mQueueLength=0
              Choreographer:
                mFrameScheduled=false
                mLastFrameTime=35169617 (5438 ms ago)
              View Hierarchy:
                DecorView@f5902b1[OtherAcitivty]
                  android.widget.LinearLayout{d9e4396 V.E...... ........ 0,0-1080,1920}
                    android.view.ViewStub{feab17 G.E...... ......I. 0,0-0,0 #1020400 android:id/action_mode_bar_stub}
                    android.widget.FrameLayout{f5a0b04 V.E...... ........ 0,60-1080,1920}
                      android.support.v7.widget.ActionBarOverlayLayout{1ca18ed V.E...... ........ 0,0-1080,1860 #7f0b004d app:id/decor_content_parent}
                        android.support.v7.widget.ContentFrameLayout{af30322 V.E...... ........ 0,168-1080,1860 #1020002 android:id/content}
                          android.support.constraint.ConstraintLayout{2b8e1b3 V.E...... ........ 0,0-1080,1692}
                        android.support.v7.widget.ActionBarContainer{eed370 V.ED..... ........ 0,0-1080,168 #7f0b004e app:id/action_bar_container}
                          android.support.v7.widget.Toolbar{2bc56e9 V.E...... ........ 0,0-1080,168 #7f0b004f app:id/action_bar}
                            android.support.v7.widget.AppCompatTextView{de22f6e V.ED..... ........ 48,43-585,124}
                            android.support.v7.widget.ActionMenuView{d5e60f V.E...... ......ID 1080,0-1080,168}
                          android.support.v7.widget.ActionBarContextView{5c5b69c G.E...... ......I. 0,0-0,0 #7f0b0050 app:id/action_context_bar}
                  android.view.View{b7a78a5 V.ED..... ........ 0,0-1080,60 #102002f android:id/statusBarBackground}
              Looper (main, tid 1) {885d47a}
                package demo.greendaotest.com.greendaotestdemo version Code: 1 version Name: 1.0 cur loop is : Looper (main, tid 1) {885d47a}
    ---------- Dump MessageQueue on Looper (main, tid 1) {885d47a}----------
               (Total messages: 0, polling=false, quitting=false)
    -------------------------- END --------------------------

              Local FragmentActivity 31cea27 State:
                mCreated=truemResumed=true mStopped=false mReallyStopped=false
                mLoadersStarted=true
              FragmentManager misc state:
                aaa@qq.com814d42b
                maaa@qq.com814d42b
                mCurState=5 mStateSaved=false mDestroyed=false

            Hist #0: ActivityRecord{59093de u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1946}
              Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.MainActivity }
              ProcessRecord{8b1d2cc 13475:demo.greendaotest.com.greendaotestdemo/u0a212}
              Local Activity beb66bb State:
                mResumed=false mStopped=true mFinished=false
                mChangingConfigurations=false
                mCurrentConfig={1.0 460mcc1mnc [zh_CN] ldltr sw360dp w360dp h620dp 480dpi nrml long port finger -keyb/v/h -nav/h s.8 themeChanged=0 themeChangedFlags=0}
                mLoadersStarted=true
                FragmentManager misc state:
                  mHost=android.app.Activity$HostCallbacks@dc5a088
                  mContainer=android.app.Activity$HostCallbacks@dc5a088
                  mCurState=3 mStateSaved=true mDestroyed=false
              ViewRoot:
                mAdded=true mRemoved=false
                mConsumeBatchedInputScheduled=false
                mConsumeBatchedInputImmediatelyScheduled=false
                mPendingInputEventCount=0
                mProcessInputEventsScheduled=false
                mTraversalScheduled=false            mIsAmbientMode=false
                android.view.ViewRootImpl$NativePreImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$ImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$NativePostImeInputStage: mQueueLength=0
              Choreographer:
                mFrameScheduled=false
                mLastFrameTime=35169617 (5453 ms ago)
              View Hierarchy:
                aaa@qq.com53efa21[MainActivity]
                  android.widget.LinearLayout{28cbe46 V.E...... .......D 0,0-1080,1920}
                    android.view.ViewStub{80a8807 G.E...... ......I. 0,0-0,0 #1020400 android:id/action_mode_bar_stub}
                    android.widget.FrameLayout{e583d34 V.E...... .......D 0,60-1080,1920}
                      android.support.v7.widget.ActionBarOverlayLayout{870175d V.E...... .......D 0,0-1080,1860 #7f0b004d app:id/decor_content_parent}
                        android.support.v7.widget.ContentFrameLayout{dc678d2 V.E...... .......D 0,168-1080,1860 #1020002 android:id/content}
                          android.widget.LinearLayout{abd9da3 V.E...... .......D 0,0-1080,1692}
                            android.support.v7.widget.AppCompatButton{7d5f8a0 VFED..C.. ......ID 0,0-515,144 #7f0b005e app:id/jump2other}
                            android.widget.LinearLayout{39bcc59 V.E...... .......D 0,144-1080,288}
                              android.support.v7.widget.AppCompatButton{76f501e VFED..C.. ......ID 12,0-276,144 #7f0b001b app:id/add}
                              android.support.v7.widget.AppCompatButton{a0270ff VFED..C.. ......ID 276,0-540,144 #7f0b005f app:id/del}
                              android.support.v7.widget.AppCompatButton{5b1fecc VFED..C.. ......ID 540,0-804,144 #7f0b0060 app:id/edit}
                              android.support.v7.widget.AppCompatButton{633d515 VFED..C.. ......ID 804,0-1068,144 #7f0b0061 app:id/query}
                            android.widget.ScrollView{23c502a VFED.V... ........ 0,288-1080,1692}
                              android.widget.RelativeLayout{e971e1b V.E...... ........ 0,0-1080,449}
                                android.support.v7.widget.AppCompatTextView{5663bb8 V.ED..... ........ 235,0-845,449 #7f0b0062 app:id/content_tv}
                            android.support.v7.widget.AppCompatButton{b09ad91 VFED..C.. ......ID 0,1692-557,1692}
                        android.support.v7.widget.ActionBarContainer{52744f6 V.ED..... ......ID 0,0-1080,168 #7f0b004e app:id/action_bar_container}
                          android.support.v7.widget.Toolbar{4ff80f7 V.E...... ........ 0,0-1080,168 #7f0b004f app:id/action_bar}
                            android.support.v7.widget.AppCompatTextView{1f5b64 V.ED..... ........ 48,43-585,124}
                            android.support.v7.widget.ActionMenuView{e8a91cd V.E...... ......ID 1080,0-1080,168}
                          android.support.v7.widget.ActionBarContextView{afaba82 G.E...... ......I. 0,0-0,0 #7f0b0050 app:id/action_context_bar}
                  android.view.View{4213593 V.ED..... ......ID 0,0-1080,60 #102002f android:id/statusBarBackground}
              Looper (main, tid 1) {885d47a}
                package demo.greendaotest.com.greendaotestdemo version Code: 1 version Name: 1.0 cur loop is : Looper (main, tid 1) {885d47a}
    ---------- Dump MessageQueue on Looper (main, tid 1) {885d47a}----------
               (Total messages: 0, polling=false, quitting=false)
    -------------------------- END --------------------------

              Local FragmentActivity beb66bb State:
                mCreated=truemResumed=false mStopped=true mReallyStopped=true
                mLoadersStarted=true
              FragmentManager misc state:
                aaa@qq.com328c9d0
                maaa@qq.com328c9d0
                mCurState=2 mStateSaved=true mDestroyed=false

        Running activities (most recent first):
          TaskRecord{48d14ff #1946 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=2}
            Run #4: ActivityRecord{59f7102 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1946}
            Run #3: ActivityRecord{59093de u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1946}

        mResumedActivity: ActivityRecord{59f7102 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1946}

      mFocusedActivity: ActivityRecord{59f7102 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1946}


搜索“task id”关键字,查看有几个栈,栈内存在的acitivity信息。

  • Task id #1946
    就一个栈,栈内2个Acitivty。

搜索“hist”关键字,查看到栈内情况。

  • Hist #1: ActivityRecord{59f7102 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1946}
  • Hist #0: ActivityRecord{59093de u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1946}

2个singleInstance启动模式的Activity,在栈内的情况

将2个Acitivity改为singleinstance。并将OtherActivity切换至前台。
Android查看任务栈


    ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
    Display #0 (activities from top to bottom):
      Stack #1:
      mResumedActivity=ActivityRecord{c5a5e13 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1956}
      mFullscreen=true
      mBounds=null
        Task id #1956
        mFullscreen=true
        mBounds=null
        mMinWidth=-1
        mMinHeight=-1
        mLastNonFullscreenBounds=null
          TaskRecord{1b945dc #1956 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=1}
          Intent { flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.OtherAcitivty }
            Hist #0: ActivityRecord{c5a5e13 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1956}
              Intent { flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.OtherAcitivty }
              ProcessRecord{353f6e5 23335:demo.greendaotest.com.greendaotestdemo/u0a212}
              Local Activity bd7ee28 State:
                mResumed=true mStopped=false mFinished=false
                mChangingConfigurations=false
                mCurrentConfig={1.0 460mcc1mnc [zh_CN] ldltr sw360dp w360dp h620dp 480dpi nrml long port finger -keyb/v/h -nav/h s.8 themeChanged=0 themeChangedFlags=0}
                mLoadersStarted=true
                FragmentManager misc state:
                  mHost=android.app.Activity$HostCallbacks@e921835
                  mContainer=android.app.Activity$HostCallbacks@e921835
                  mCurState=5 mStateSaved=false mDestroyed=false
              ViewRoot:
                mAdded=true mRemoved=false
                mConsumeBatchedInputScheduled=false
                mConsumeBatchedInputImmediatelyScheduled=false
                mPendingInputEventCount=0
                mProcessInputEventsScheduled=false
                mTraversalScheduled=false            mIsAmbientMode=false
                android.view.ViewRootImpl$NativePreImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$ImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$NativePostImeInputStage: mQueueLength=0
              Choreographer:
                mFrameScheduled=false
                mLastFrameTime=35865498 (12583 ms ago)
              View Hierarchy:
                aaa@qq.com592a4ca[OtherAcitivty]
                  android.widget.LinearLayout{be1e63b V.E...... ........ 0,0-1080,1920}
                    android.view.ViewStub{ff73158 G.E...... ......I. 0,0-0,0 #1020400 android:id/action_mode_bar_stub}
                    android.widget.FrameLayout{f5902b1 V.E...... ........ 0,60-1080,1920}
                      android.support.v7.widget.ActionBarOverlayLayout{d9e4396 V.E...... ........ 0,0-1080,1860 #7f0b004d app:id/decor_content_parent}
                        android.support.v7.widget.ContentFrameLayout{feab17 V.E...... ........ 0,168-1080,1860 #1020002 android:id/content}
                          android.support.constraint.ConstraintLayout{f5a0b04 V.E...... ........ 0,0-1080,1692}
                        android.support.v7.widget.ActionBarContainer{1ca18ed V.ED..... ........ 0,0-1080,168 #7f0b004e app:id/action_bar_container}
                          android.support.v7.widget.Toolbar{af30322 V.E...... ........ 0,0-1080,168 #7f0b004f app:id/action_bar}
                            android.support.v7.widget.AppCompatTextView{2b8e1b3 V.ED..... ........ 48,43-585,124}
                            android.support.v7.widget.ActionMenuView{eed370 V.E...... ......ID 1080,0-1080,168}
                          android.support.v7.widget.ActionBarContextView{2bc56e9 G.E...... ......I. 0,0-0,0 #7f0b0050 app:id/action_context_bar}
                  android.view.View{de22f6e V.ED..... ........ 0,0-1080,60 #102002f android:id/statusBarBackground}
              Looper (main, tid 1) {d5e60f}
                package demo.greendaotest.com.greendaotestdemo version Code: 1 version Name: 1.0 cur loop is : Looper (main, tid 1) {d5e60f}
    ---------- Dump MessageQueue on Looper (main, tid 1) {d5e60f}----------
               (Total messages: 0, polling=false, quitting=false)
    -------------------------- END --------------------------

              Local FragmentActivity bd7ee28 State:
                mCreated=truemResumed=true mStopped=false mReallyStopped=false
                mLoadersStarted=true
              FragmentManager misc state:
                aaa@qq.com5c5b69c
                maaa@qq.com5c5b69c
                mCurState=5 mStateSaved=false mDestroyed=false
        Task id #1953
        mFullscreen=true
        mBounds=null
        mMinWidth=-1
        mMinHeight=-1
        mLastNonFullscreenBounds=null
          TaskRecord{a1815ba #1953 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=1}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.MainActivity }
            Hist #0: ActivityRecord{590df4d u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1953}
              Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.MainActivity }
              ProcessRecord{353f6e5 23335:demo.greendaotest.com.greendaotestdemo/u0a212}
              Local Activity beb66bb State:
                mResumed=false mStopped=true mFinished=false
                mChangingConfigurations=false
                mCurrentConfig={1.0 460mcc1mnc [zh_CN] ldltr sw360dp w360dp h620dp 480dpi nrml long port finger -keyb/v/h -nav/h s.8 themeChanged=0 themeChangedFlags=0}
                mLoadersStarted=true
                FragmentManager misc state:
                  mHost=android.app.Activity$HostCallbacks@b7a78a5
                  mContainer=android.app.Activity$HostCallbacks@b7a78a5
                  mCurState=3 mStateSaved=true mDestroyed=false
              ViewRoot:
                mAdded=true mRemoved=false
                mConsumeBatchedInputScheduled=false
                mConsumeBatchedInputImmediatelyScheduled=false
                mPendingInputEventCount=0
                mProcessInputEventsScheduled=false
                mTraversalScheduled=false            mIsAmbientMode=false
                android.view.ViewRootImpl$NativePreImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$ImeInputStage: mQueueLength=0
                android.view.ViewRootImpl$NativePostImeInputStage: mQueueLength=0
              Choreographer:
                mFrameScheduled=false
                mLastFrameTime=35865498 (12605 ms ago)
              View Hierarchy:
                aaa@qq.com885d47a[MainActivity]
                  android.widget.LinearLayout{814d42b V.E...... .......D 0,0-1080,1920}
                    android.view.ViewStub{dc5a088 G.E...... ......I. 0,0-0,0 #1020400 android:id/action_mode_bar_stub}
                    android.widget.FrameLayout{53efa21 V.E...... .......D 0,60-1080,1920}
                      android.support.v7.widget.ActionBarOverlayLayout{28cbe46 V.E...... .......D 0,0-1080,1860 #7f0b004d app:id/decor_content_parent}
                        android.support.v7.widget.ContentFrameLayout{80a8807 V.E...... .......D 0,168-1080,1860 #1020002 android:id/content}
                          android.widget.LinearLayout{e583d34 V.E...... ......ID 0,0-1080,1692}
                            android.support.v7.widget.AppCompatButton{870175d VFED..C.. ......ID 0,0-515,144 #7f0b005e app:id/jump2other}
                            android.widget.LinearLayout{dc678d2 V.E...... .......D 0,144-1080,288}
                              android.support.v7.widget.AppCompatButton{abd9da3 VFED..C.. ......ID 12,0-276,144 #7f0b001b app:id/add}
                              android.support.v7.widget.AppCompatButton{7d5f8a0 VFED..C.. ......ID 276,0-540,144 #7f0b005f app:id/del}
                              android.support.v7.widget.AppCompatButton{39bcc59 VFED..C.. ......ID 540,0-804,144 #7f0b0060 app:id/edit}
                              android.support.v7.widget.AppCompatButton{76f501e VFED..C.. ......ID 804,0-1068,144 #7f0b0061 app:id/query}
                            android.widget.ScrollView{a0270ff VFED.V... ........ 0,288-1080,1692}
                              android.widget.RelativeLayout{5b1fecc V.E...... ........ 0,0-1080,449}
                                android.support.v7.widget.AppCompatTextView{633d515 V.ED..... ........ 235,0-845,449 #7f0b0062 app:id/content_tv}
                            android.support.v7.widget.AppCompatButton{23c502a VFED..C.. ......ID 0,1692-557,1692}
                        android.support.v7.widget.ActionBarContainer{e971e1b V.ED..... ......ID 0,0-1080,168 #7f0b004e app:id/action_bar_container}
                          android.support.v7.widget.Toolbar{5663bb8 V.E...... ........ 0,0-1080,168 #7f0b004f app:id/action_bar}
                            android.support.v7.widget.AppCompatTextView{b09ad91 V.ED..... ........ 48,43-585,124}
                            android.support.v7.widget.ActionMenuView{52744f6 V.E...... ......ID 1080,0-1080,168}
                          android.support.v7.widget.ActionBarContextView{4ff80f7 G.E...... ......I. 0,0-0,0 #7f0b0050 app:id/action_context_bar}
                  android.view.View{1f5b64 V.ED..... ......ID 0,0-1080,60 #102002f android:id/statusBarBackground}
              Looper (main, tid 1) {d5e60f}
                package demo.greendaotest.com.greendaotestdemo version Code: 1 version Name: 1.0 cur loop is : Looper (main, tid 1) {d5e60f}
    ---------- Dump MessageQueue on Looper (main, tid 1) {d5e60f}----------
               (Total messages: 0, polling=false, quitting=false)
    -------------------------- END --------------------------

              Local FragmentActivity beb66bb State:
                mCreated=truemResumed=false mStopped=true mReallyStopped=true
                mLoadersStarted=true
              FragmentManager misc state:
                mHost=android.support.v4.app.FragmentActivity$HostCallbacks@e8a91cd
                mContainer=android.support.v4.app.FragmentActivity$HostCallbacks@e8a91cd
                mCurState=2 mStateSaved=true mDestroyed=false

        Running activities (most recent first):
          TaskRecord{1b945dc #1956 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=1}
            Run #3: ActivityRecord{c5a5e13 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1956}
          TaskRecord{a1815ba #1953 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=1}
            Run #2: ActivityRecord{590df4d u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1953}

        mResumedActivity: ActivityRecord{c5a5e13 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1956}

      mFocusedActivity: ActivityRecord{c5a5e13 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1956}

这里得多唠叨下:

搜索“task id”关键字,查看有几个栈,栈内存在的acitivity信息。

这里可以看到是2个栈:

  • Task id #1956 ,Task id #1953。
  • 每个栈内存在一个activity,分别是。
 Task id #1956
    mFullscreen=true
    mBounds=null
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
      TaskRecord{1b945dc #1956 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=1}
      Intent { flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.OtherAcitivty }
        Hist #0: ActivityRecord{c5a5e13 u0 demo.greendaotest.com.greendaotestdemo/.OtherAcitivty t1956}

Task id #1953
    mFullscreen=true
    mBounds=null
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
      TaskRecord{a1815ba #1953 A=demo.greendaotest.com.greendaotestdemo U=0 StackId=1 sz=1}
      Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=demo.greendaotest.com.greendaotestdemo/.MainActivity }
        Hist #0: ActivityRecord{590df4d u0 demo.greendaotest.com.greendaotestdemo/.MainActivity t1953}

本文分析的文件:
https://download.csdn.net/download/user11223344abc/10367965