Is there a way to print the current back stack of the current task in an Android app? In particular, I want to understand when an activity is popped off the stack after its onDestroy() is called.
Asked
Active
Viewed 9,498 times
5 Answers
30
To improve on Paul's answer and see data relevant to your app only you can do:
adb shell dumpsys activity package <your.package.name>

Christopher Perry
- 38,891
- 43
- 145
- 187

sham
- 1,346
- 1
- 20
- 28
16
Use the command below can show tasks and activity backstack
adb shell dumpsys activity activities | sed -En -e '/Running activities/,/Run #0/p'
And result looks like this:
Running activities (most recent first):
TaskRecord{29b17859 #1134 A=com.google.android.dialer U=0 sz=1}
Run #0: ActivityRecord{180fd6be u0 com.google.android.dialer/.extensions.GoogleDialtactsActivity t1134}
Running activities (most recent first):
TaskRecord{7764a61 #1054 A=com.google.android.googlequicksearchbox U=0 sz=1}
Run #1: ActivityRecord{2900994b u0 com.google.android.googlequicksearchbox/com.google.android.launcher.GEL t1054}
TaskRecord{4aa804c #1129 A=com.android.systemui U=0 sz=1}
Run #0: ActivityRecord{1816140b u0 com.android.systemui/.recents.RecentsActivity t1129}

Euporie
- 1,896
- 1
- 21
- 23
-
This is not working for unfortunately. Maybe the OS has changed its logging format or maybe yours is a customized OS? – ericn Dec 19 '22 at 13:29
6
If just want to look Activity backstack use below set commands
adb shell
dumpsys activity | grep -i run

Amit Yadav
- 32,664
- 6
- 42
- 57
5
You can use adb for this:
adb shell dumpsys activity

Paul
- 5,163
- 3
- 35
- 43
-
3There's a lot of information printed out. Which part should I focus on? I don't seem to find a description of task stacks. – dacongy Jul 19 '12 at 20:38
0
Answer from sham is great
adb shell dumpsys activity package <your.package.name>
but if you want narrow things down even further, I believe the following 2 sections are most relevant:
ACTIVITY MANAGER RECENT TASKS (dumpsys activity recents)
mRecentsUid=10130
mRecentsComponent=ComponentInfo{com.google.android.apps.nexuslauncher/com.android.quickstep.RecentsActivity}
mFreezeTaskListReordering=false
mFreezeTaskListReorderingPendingTimeout=false
Recent tasks:
* Recent #0: Task{41d503 #1068 type=standard A=10287:app.ericn.myapp U=0 visible=true mode=fullscreen translucent=false sz=2}
Visible recent tasks (most recent first):
* RecentTaskInfo #0:
id=1068 userId=0 hasTask=true lastActiveTime=109671463
baseIntent=Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=app.ericn.myapp/.MainActivity }
baseActivity={app.ericn.myapp/app.ericn.myapp.MainActivity}
topActivity={app.ericn.myapp/app.ericn.myapp.SecondActivity}
realActivity={app.ericn.myapp/app.ericn.myapp.MainActivity}
isExcluded=false activityType=standard windowingMode=fullscreen supportsSplitScreenMultiWindow=true supportsMultiWindow=true
taskDescription { colorBackground=#ffffffff colorPrimary=#ff6200ee iconRes=/0 iconBitmap=false resizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION minWidth=-1 minHeight=-1 colorBackgroundFloating=#ffffffff }
lastSnapshotData { taskSize=Point(1080, 2280) contentInsets=Rect(0, 83 - 0, 132) bufferSize=Point(864, 1824) }
...
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Display #0 (activities from top to bottom):
mResumedActivity: ActivityRecord{10684b5 u0 app.ericn.myapp/.SecondActivity t1068}
RootTask #1068: type=standard mode=fullscreen
isSleeping=false
mBounds=Rect(0, 0 - 0, 0)
mCreatedByOrganizer=false
* Task{41d503 #1068 type=standard A=10287:app.ericn.myapp U=0 visible=true mode=fullscreen translucent=false sz=2}
mBounds=Rect(0, 0 - 0, 0)
mMinWidth=-1 mMinHeight=-1
userId=0 effectiveUid=u0a287 mCallingUid=2000 mUserSetupComplete=true mCallingPackage=com.android.shell mCallingFeatureId=null
affinity=10287:app.ericn.myapp
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=app.ericn.myapp/.MainActivity}
mActivityComponent=app.ericn.myapp/.MainActivity
autoRemoveRecents=false isPersistable=true activityType=1
rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
Activities=[ActivityRecord{da73511 u0 app.ericn.myapp/.MainActivity t1068}, ActivityRecord{10684b5 u0 app.ericn.myapp/.SecondActivity t1068}]
askedCompatMode=false inRecents=true isAvailable=true
mRootProcess=ProcessRecord{e2571b2 24749:app.ericn.myapp/u0a287}
taskId=1068 rootTaskId=1068
hasChildPipActivity=false
mHasBeenVisible=true
mResizeMode=RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION mSupportsPictureInPicture=false isResizeable=true
lastActiveTime=109671463 (inactive for 3s)
Hist #1: ActivityRecord{10684b5 u0 app.ericn.myapp/.SecondActivity t1068}
Intent { cmp=app.ericn.myapp/.SecondActivity }
ProcessRecord{e2571b2 24749:app.ericn.myapp/u0a287}
Hist #0: ActivityRecord{da73511 u0 app.ericn.myapp/.MainActivity t1068}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=app.ericn.myapp/.MainActivity }
Resumed activities in task display areas (from top to bottom):
Resumed: ActivityRecord{10684b5 u0 app.ericn.myapp/.SecondActivity t1068}
ResumedActivity: ActivityRecord{10684b5 u0 app.ericn.myapp/.SecondActivity t1068}

ericn
- 12,476
- 16
- 84
- 127