How to emulate unloading background application on Android OS?

For testing purposes, I need to easily reproduce a situation where the Android system decides to save state and kill the background application in the same way as it is usually done to optimize memory. In fact, I also need to test the recovery process of such a remote process when the user switches to it.

The incoherence based approach is to open the application and then open other tasks, trying to allocate as many resources as possible. It is too complicated and unreliable.

I found this question on SO , but the answer implies simply killing the process, which seems not equivalent, because there is no means for further automatic recovery of the killed process with the saved state when the user decides to return to the application. If I understand correctly, after such an explicit killing of the application, if it is running, it will be launched from the very beginning, and not from the saved state. Please correct me if I am wrong.

According to the Android documentation, I need to execute ActivityManager.killBackgroundProcesses(packageName) , but this is a programmatic way to do this. Is there a utility that already provides the same feature from the user interface?

+6
source share
1 answer

If I understood correctly, after such an explicit killing of the application, if it is running, it will be launched from the very beginning, and not from the saved state.

It depends on how the application starts. If you mean from the launcher icon, yes. However, the user can return to you using the BACK button or by using a list of recent tasks, depending on the circumstances, and they will return the user to the place they left, rather than the "very beginning".

Is there a utility that already provides the same option from the UI?

On an Android 4.0+ device with your application in the background, open the list of recent tasks (press the HOME button or press the highlighted RECENTS version) and swipe right on the screen. This is basically called killBackgroundProcesses() for this package name.

I have not tried this in an emulator, but it probably does the same thing.

+3
source

All Articles