Marcelo Marcelo - 1 year ago 295
Android Question

How to close an Android app using UiAutomator?

How can I close an especific Android app using UiAutomator API?
Like when you manually press the Recents button and swipe the app you want to close.

Answer Source

The best option would be to use getUiDevice.pressRecentApps, this will load up the recent apps for you, then take a screenshot using the uiautomator viewerso you have a view of the xml of the screen that has been loaded. You can then use this xml to select the object you wish to swipe using

UiObject app = new UIObject(new UiSelector().resourceId("The id of the app");

or right

This should be able to close your app. The xml will depend on what style of android you are using and the device.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download