Home » Android » adb shell command to get Current Activity Name (Foreground / Top Activity ) ?

adb shell command to get Current Activity Name (Foreground / Top Activity ) ?

Most of the time during development, when you encounter with some unknown applications from which you want to start their activity or take some actions based on the currently running activity of that application. In those scenarios we first need to identify what is the package and activity of the said application in question.

Android 10 and Afterwords

$ adb shell dumpsys activity a . | grep -E 'mResumedActivity' | cut -d ' ' -f 8

OR

$ adb shell dumpsys window windows | grep mActivityRecord

OR

$ adb shell dumpsys activity activities | grep "mFocused"

The above commands which show the package name of the application currently active and the foreground activity name.

Before Android 10

In Android, you can identify currently displayed activity name using below command, ( For that first open your application activity )

$ adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' 
mCurrentFocus=Window{8d0c629 u0 com.example.myapplication/com.example.myapplication.MainActivity}
  mFocusedApp=AppWindowToken{6926e80 token=Token{a2cbf03 ActivityRecord{6a1c3b2 u0 com.example.myapplication/.MainActivity t5430}}}

As you can see above, the currently running application package name is “com.example.myapplication” and its activity which in on top of activity stack is “MainActivity” in package “com.example.myapplication”


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment