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.

@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