Issue
In the flow diagram for an Android app activity lifecycle (shown below) there is a route by which the 'App process' is killed and onDestroy() is not called. It seems this is most commonly done to free up memory resources for a different activity.
All that is fine, but how do I test this scenario? Either on device or in the simulator.
Solution
If you force stop your app, all BroadcastReceivers and also app widgets, which extend BroadcastReceiver, will stop working. See also this SO post by Commonsware
So force stopping the app is not ideal for testing app behavior under low memory conditions. What else can you do?
- One option: write your own task killer app and use ActivityManager.killBackgroundProcesses(). As the documentation says:
This is the same as the kernel killing those processes to reclaim memory
- Another option: manipulate the device settings as explained by Xavi Gil in his answer to Simulate low battery & low memory in Android
Answered By - Bö macht Blau

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.