Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Last active March 18, 2025 07:25
Show Gist options
  • Save zulhfreelancer/96b97a641a5396198a063c61d9eddcc0 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/96b97a641a5396198a063c61d9eddcc0 to your computer and use it in GitHub Desktop.
ADB command to show Android app package & main activity name running in a connected real device
$ adb shell dumpsys activity activities | sed -En -e '/Stack #/p' -e '/Running activities/,/Run #0/p'
$ 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.

@schrmh
Copy link

schrmh commented Jan 26, 2023

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:

com.android.systemui/.recents.RecentsActivity
com.deepl.mobiletranslator/.MainActivity
com.github.libretube/.ui.activities.MainActivity
com.mi.android.globallauncher/com.miui.home.launcher.Launcher
net.wrightflyer.le.reality/.features.main.MainActivity

(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:

      Activities=[ActivityRecord{d1a1b1d u999 net.wrightflyer.le.reality/.features.main.MainActivity t99900016}]
      Activities=[ActivityRecord{1540a70 u0 net.wrightflyer.le.reality/.features.main.MainActivity t1286}]
      Activities=[ActivityRecord{6d937e5 u0 com.mi.android.globallauncher/com.miui.home.launcher.Launcher t1}]
      Activities=[ActivityRecord{401ec99 u0 com.android.systemui/.recents.RecentsActivity t1234}]
      Activities=[ActivityRecord{a5689c6 u0 com.github.libretube/.ui.activities.MainActivity t1260}]
      Activities=[ActivityRecord{185ffdb u0 com.deepl.mobiletranslator/.MainActivity t1261}]

(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

@kakooloukia
Copy link

Hi there,

We can remove duplicates without losing the stack order using merge:
adb shell dumpsys activity activities | grep mActivityComponent | cut -d= -f2 | sort -u -m

-u, --unique

with -c, check for strict ordering
without -c, output only the first of an equal run

-m, --merge

merge already sorted files; do not sort

Thank you @schrmh schrmh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment