Adrian Grigore
Adrian Grigore

Reputation: 33318

Android Simulator: Easy way to simulate a process restart due to low memory?

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

Answers (4)

DustinB
DustinB

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

jmng
jmng

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

tidbeck
tidbeck

Reputation: 2408

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

Upvotes: 10

numan salati
numan salati

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

Related Questions