Saturday, April 14, 2018

Simulate the android background process killed by memory shortage

It is useful to test the use case when Android process gets killed by OS due to device memory shortage.

1. Optionally, open Android device monitor to check the status of the process
2. Put the application in background by press home button
3. run the below adb command to kill the process based on the package name

adb shell am kill com.company.myassistantproject
alternatively, you can also kill the process from Android Device Monitor by selecting tthe process and then click "stop" button.
4. optionally, verify the process is killed from Android Device Monitor.
5. Restart the app by clicking the app icon in home button, or bring up the recent app screens and then select the application.

Not if one process's activity A starts another process's activity B. And then process A gets killed by OS due to memory shortage. If Activity B sends result back to Activity A using setResult method, then Android OS will automatically start activity A again and pass the result to it.

However, if the activity A is closed by calling finish method, or if it wiped out of memory by user, then when Activity B calls setResult, and Android OS will ignore the result, and will not create Activity A to receive the result.

No comments:

Post a Comment