Simulate Killing of Activity in Emulator

Simulate killing of activity in emulator

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.

How to simulate Android killing app caused by low memory in AndroidStudio 4

I found the way:

Since AndroidStudio 4, if you run the app from AndroidStudio play button, logcat terminate button will simulate a complete stop of the app, instead of a low memory kill.

The solution is launching the app from the icon in the emulator, them that terminate button will simulate the low memory kill correctly.

Simulating activity death in Android

Rotate your device (or emulator). Android saves, destroys, and re-creates the activity in the new orientation.

How to simulate a service killed by the Android system

if you're developing in Android Studio while you are running your application in android wear side try to hit the kill button displayed in the console.

Kill app button

When you hit this button all the threads + services + activities from this app will be destroyed. If your service is of type "STICKY" it will start by itself after you kill your application.

Simulate Android application flushed out of memory

I'd be surprised if your activity isn't also getting onCreate in those situations. A strategy for testing this kind of thing on the emulator is to pause all activities in your application and then using adb to kill the process. That's basically what the framework does when it runs short of resources. When you resume the activity, it creates a new process and tries to reinitialize your activity from the state that was saved when it was paused.

kill a process running in the android emulator

If you want to kill without ddms :

Use this to list the processes and their pid's

adb shell ps 

and go for the kill using

adb shell kill <PID>

Where <PID> is the Process you want to kill (int)



Related Topics



Leave a reply



Submit