[android] ADB - Android - Getting the name of the current activity

Is there a way to get the details of the current activity that is running via adb.

This question is related to android adb ddms

The answer is


In windows, this command works for me to show current activity name

adb shell dumpsys window windows | find "mCurrentFocus"

Output:

mCurrentFocus=Window{a43a55b u0 com.android.contacts/com.android.contacts.activities.TwelveKeyDialer}

Other solutions with "grab" produce error in my windows pc

'grep' is not recognized as an internal or external command, operable program or batch file.

So, using "find" solve the error in my case.


I prefer parsing results of dumpsys window windows over dumpsys activity

adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'

Keyguard or Recent tasks list used to not show up as Activities but you were able to see them with mCurrentFocus. I have explained why in this answer.


Here is a solution that is easier than the command line adb solution (which does work). It is easier because it is more graphical and can be done from within Eclipse.

In Eclipse with Android device attached go to Window menu > Show View > Other ... use filter text "Windows" to pull up Android > Windows ... show this. The top item in the list is the current activity.

Another way to pull this up is by showing the "Hierarchy View" perspective, which by default will show the Windows window.


This works for me:

adb shell dumpsys activity

And this to show current activity name:

adb shell dumpsys activity activities | grep mFocusedActivity | cut -d . -f 5 | cut -d ' ' -f 1


Android Q broke most of these for me. Here's a new one that seems to be working (at least on Android Q).

adb shell "dumpsys activity activities | grep mResumedActivity"

Output looks like:

mResumedActivity: ActivityRecord{7f6df99 u0 com.sample.app/.feature.SampleActivity t92}

Edit: Works on Android R for me as well


Old answers stopped working in new android versions. Now I use the following:

adb shell "dumpsys activity activities | grep ResumedActivity"

dumpsys window windows gives more detail about the current activity:

adb shell "dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'"
  mCurrentFocus=Window{41d2c970 u0 com.android.launcher/com.android.launcher2.Launcher}
  mFocusedApp=AppWindowToken{4203c170 token=Token{41b77280 ActivityRecord{41b77a28 u0 com.android.launcher/com.android.launcher2.Launcher t3}}}

However in order to find the process ID (e.g. to kill the current activity), use dumpsys activity, and grep on "top-activity":

adb shell "dumpsys activity | grep top-activity"
    Proc # 0: fore  F/A/T  trm: 0 3074:com.android.launcher/u0a8 (top-activity)

adb shell "kill 3074"

Below command can be used for finding both package and current Activity name. Found this very useful command to quickly fetch these two information about an app especially when developing tests with Appium.

adb shell dumpsys window windows | grep -E 'mCurrentFocus'

Response of this command contains both package name and current Activity. For example: in following "com.android.contacts" is the package and "com.android.contacts.activities.TwelveKeyDialer" is current Activity launched on the phone which is connected via adb.

mCurrentFocus=Window{2089af8 u0 com.android.contacts/com.android.contacts.activities.TwelveKeyDialer}

Reference: http://www.automationtestinghub.com/apppackage-and-appactivity-name/


You can try this command,

adb shell dumpsys activity recents

There you can find current activity name in activity stack.

To get most recent activity name:

adb shell dumpsys activity recents | find "Recent #0"

If you want to filter out only your app's activities currently running/paused, you can use this command:

adb shell dumpsys activity activities | grep 'Hist #' | grep 'YOUR_PACKAGE_NAME'

For example:

adb shell dumpsys activity activities | grep 'Hist #' | grep 'com.supercell.clashroyale'

The output will be something like:

* Hist #2: ActivityRecord{26ba44b u10 com.supercell.clashroyale/StartActivity t27770}
* Hist #1: ActivityRecord{2f3a0236 u10 com.supercell.clashroyale/SomeActivity t27770}
* Hist #0: ActivityRecord{20bbb4ae u10 com.supercell.clashroyale/OtherActivity t27770}

Do notice that the output shows the actual stack of activities i.e. the topmost activity is the one that is currently being displayed.