$ adb shell dumpsys activity activities | sed -En -e '/Stack #/p' -e '/Running activities/,/Run #0/p'
Stack #1:
Running activities (most recent first):
TaskRecord{c90e20c #265 A=com.hootsuite.droid.full U=0 sz=1}
Run #0: ActivityRecord{ec0802b u0 com.hootsuite.droid.full/.app.ui.DockingActivity t265}
Stack #0:
Running activities (most recent first):
TaskRecord{55974a7 #211 A=com.huawei.android.launcher U=0 sz=1}
Run #0: ActivityRecord{586f966 u0 com.huawei.android.launcher/.Launcher t211}
So, in above case, the app package is com.hootsuite.droid.full
and the main activity is .app.ui.DockingActivity
.
Some apps open in the background do not show up by using that.
Slight modification and they do.
E.g. to get app package name with activity names of all open apps:
adb shell dumpsys activity activities | grep mActivityComponent | cut -d= -f2 | sort -u
Example output:
(RecentsActivity and Launcher will be always there for me)
A bit more information (e.g. user ID which might be useful if you have cloned app)
adb shell dumpsys activity activities | grep "Activities=\["
Example output:
(
net.wrightflyer.le.reality
is indeed started two times using clone feature)Also I noticed that it might not update sometimes if RecentsActivity is in foreground