Feb 26, 2011

How to test behavior of a killed Android application

Background
The Android application doesn't always continue to run in same process. When an user run your application and others same time, and one of other applications requires more memory, then there is a possibility that the process of your application is killed. Later, your application are started in a new process and activities are recreated when the user re-launch your application.
But the user doesn't know your application process was killed. So, your application should be shown the same as before. To resume the state of last time, you need to implement and test storing/restoring application data.

But how can we easily test that situation?

This post explains how to test behavior of a killed Android application with Android emulator.


Testing behavior of a killed Android application
The most easy way to test, launch your application, show any activity and rotate emulator with Ctrl+F11 or Ctrl+F12.
When an Android device is rotated, activities are recreated. This is the same situation as Android application is killed and restartd.

But, if you prevent rotation your activity, you can't use above technique.
In this case, first, launch your application, show any activity and back to home with Home button or launch another application.

Next, kill your application process with ddms or adb (that is the same situation as Android kills your application to collect memory).
If you want to use ddms (or Eclipse ddms perspective), select process which you want to kill and push stop button.
Kill any process with DDMS perspective of Eclipse

If you want to use adb,
  1. launch "adb shell".
  2. find PID of the process which you want to kill with "ps"
  3. execute "kill PID"

Finally, re-launch your application. Android starts it in new process and recreate your activity.

No comments:

Post a Comment