Closing a window within an activity using adb shell commands I have been tinkering around with adb and attempting to control an application and close popup windows using adb shell commands. I trying to close an activity window that I can identify with the following command:

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


which returns two different variables while the window I want to close is open:

mCurrentFocus=Window{4e8ee3f u0 myApp/myActivity} (this is what I want to close)
mFocusedApp=AppWindowToken{ee23799 token=Token{5208e0 ActivityRecord{4dac6e3 u0 myApp/myActity}}}


Is it possible to close the current focus window and if so how?
When it comes to closing a dialog or a window, a user uses the Back key of their device. Through command-line you can emulate the functionality of Back key using a particular key event. The key event for Back key is KEYCODE_BACK. It has the constant value 4. Use it with input command in this manner:

adb shell input keyevent KEYCODE_BACK
adb shell input keyevent 4    # alternative


I recommend you read this answer by Rene Barbosa. It lists many useful key events. I also recommend you execute adb shell input to find out how useful that command can be.