Android Simulator: Easy way to simulate a process restart due to low memory?
Solution 1
Found two similar questions Simulate killing of activity in emulator and Simulate low battery & low memory in Android.
Solutions from those questions:
- Use
adb shell
and thenkill
the process withPID
fromps
- Kill it using DDMS
Solution 2
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.
Solution 3
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."
Solution 4
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
Adrian Grigore
I'm a freelancer software developer from Germany specializing in ASP.NET MVC and related technlogies. Send me a message if you are interested in hiring me for development / consulting services. My current main project is a web-based, team-oriented project time tracking software for desktop and mobile devices: LogMyTime Zeiterfassung. Adrian Grigore's Blog on Software Development
Updated on June 11, 2022Comments
-
Adrian Grigore almost 2 years
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.
-
Adrian Grigore about 11 yearsThanks! I'll check this next time I am updating my Android App.
-
ZakTaccardi over 7 yearsthis tests a configuration change - not a process restart. these are two different things.
-
Nishant Pardamwar almost 7 yearsDo not keep activities wont destroy the global app context, we want to be able to destroy the global app context so that at rerun it will try to start from application onCreate() and starts the last opened activity