17

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
  • 33,034
  • 36
  • 130
  • 210
  • Does this differ from killing your own process `android.os.Process.killProcess(android.os.Process.myPid())`? – tidbeck Jan 03 '12 at 13:03
  • @tidbeck: Your guess is as good as mine. I am referring to this article: http://android-developers.blogspot.com/2010/04/multitasking-android-way.html – Adrian Grigore Jan 03 '12 at 18:52
  • possible duplicate of [Android: How to force restart service (OS killing on low memory behavior)](http://stackoverflow.com/questions/7257378/android-how-to-force-restart-service-os-killing-on-low-memory-behavior) – Flow Sep 05 '13 at 10:22

4 Answers4

10

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 then kill the process with PID from ps
  • Kill it using DDMS
Community
  • 1
  • 1
tidbeck
  • 2,363
  • 24
  • 35
5

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.

Community
  • 1
  • 1
numan salati
  • 19,394
  • 9
  • 63
  • 66
3

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
DustinB
  • 11,037
  • 5
  • 46
  • 54
2

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."

jmng
  • 2,479
  • 1
  • 25
  • 38