Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate killing of activity in emulator

Tags:

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

like image 467
SteD Avatar asked Mar 13 '11 03:03

SteD


People also ask

How to simulate android killing my process?

You can actually simulate process death by putting your application in the background with HOME, then pressing “Terminate application” in Android Studio. Then restart from launcher.

What is process death Android?

ViewModels are automatically destroyed by the system when your user backs out of your activity or fragment or if you call finish() , which means the state will be cleared as the user expects in these scenarios. Unlike saved instance state, ViewModels are destroyed during a system-initiated process death.

How does emulator help in the running of an app?

The emulator provides almost all of the capabilities of a real Android device. You can simulate incoming phone calls and text messages, specify the location of the device, simulate different network speeds, simulate rotation and other hardware sensors, access the Google Play Store, and much more.


1 Answers

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.

like image 186
Ted Hopp Avatar answered Nov 27 '22 19:11

Ted Hopp