Reputation: 33318
As I just learned, Android reserves the right to kill a background application's process at any moment in order to recycle RAM. The application is still running and can be resumed nevertheless, but all of my static variables are gone (see this article).
I'd like to simulate my app's behavior in this scenario. What's the easiest way to do this? There certainly must be an easier and more predictable way than writing some additional apps that allocate lots of memory.
Upvotes: 17
Views: 12310
Reputation: 11284
To kill background processes (but still relaunch via history), you can just use activity manager shell command on simulator or device:
$ adb shell am kill com.my.package
Upvotes: 3
Reputation: 2568
An alternative way is to build a super basic app that calls killBackgroundProcesses() for your package, because this method "is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed."
Upvotes: 2
Reputation: 2408
Found two similar questions Simulate killing of activity in emulator and Simulate low battery & low memory in Android.
Solutions from those questions:
adb shell
and then kill
the process with PID
from ps
Upvotes: 10
Reputation: 19494
short answer: change orientation if you are using an emulator. if using actual device, change settings by going to settings --> developer options --> don't keep activities.
see my answer to this and this for detailed explanation.
Upvotes: 6