Simulate killing of activity in emulator

SteD picture SteD · Mar 13, 2011 · Viewed 14.7k times · Source

I would like to test out onSaveInstanceState and onRestoreInstanceState for my app on the emulator.

I have found this, which says that we could simulate this during orientation change, but I'm storing some of my variables on the application level (subclass android.app.Application), so the orientation change does not wipe out the variables.

So my question is, how can I simulate the low memory situation thus killing of my activities?

Hope I've made myself clear. Thanks

Answer

Ted Hopp picture Ted Hopp · Mar 13, 2011

You can pause your application (by pushing the Home button, simulating a call, whatever). Then kill the app's process through adb. Since the docs say that after onPause() returns your app can be killed without any further notice, this is a fair test.

If you don't want to go through the trouble of finding the pid of your app's process, you can use adb shell am kill com.example.package_name to kill your app's process. Make sure that the app is put in the background. The docs say that this command "kills only processes that are safe to kill and that will not impact the user experience." So you might want to launch a couple of other apps before trying this one.