Reputation: 1291
How can I test or emulate what happens to my application when Android runs out of memory and kills my app? Is there a way to force it to test and debug?
EDIT: Usually the bug I am seeing is when my application dies because the user goes to other programs and returns to mine after a while, so i want to easily test that scenario
Thanks
Upvotes: 3
Views: 360
Reputation: 486
Yes run a bunch of stuff on your computer to get it to lag works for me. Do this to get it to do some thing on low memory like quit app. This will close app with all activities.
@Override
public void onLowMemory() {
android.os.Process.killProcess(android.os.Process.myPid())
}
Upvotes: 1
Reputation: 526
Improperly load a bunch of bitmap files. ;)
Just kidding. You should just be able to throw a new OutOfMemoryError in the part of your code that you want to test. I haven't tried it, but I believe that should do what you're wanting.
If you want to see the code in the debugger when that exception is thrown, set a break point right before the throw new OutOfMemoryError();
line.
Upvotes: 0