Android close app from app switch


I’ve noticed that driver.terminateApp() or driver.closeApp() are too “aggressive”.
It kills the app no matter the state, similar to force stopping it from the app info ui page, which sometimes causes for crash logs in the device logcat.

I would like to simulate a real user scenario for closing the app from the switch apps menu.

I wondered if you have an idea about how to close the app gracefully without using terminateApp?


Could try with adb:

adb shell am force-stop [PACKAGE]

But that might also generate crash logs. If so you could ask developers to help. Maybe a ‘debug’ log in test app that lets you quiesce the app before termination. Be aware that you may be looking at a bug in the app since it’s generating crash logs. At the very least I’d have a conversation about this. Might want to test and make sure that closing from switch apps menu doesn’t also generate these crash logs.

You could do it same way a user does: open apps menu, select your app from the list and swipe up to close it

@wreed, thanks I’ll will verify that closing the app from the app switch is not producing crash logs as well.
@mykola-mokhnach, Trying to close the app from the switch app, unfortunately not all devices vendors are the same.