adb shell command for knowing name of the current running activity on top

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.

In Android, you can identify currently displaed 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”

Leave a Comment