Totic
Totic

Reputation: 1291

Test android killing application when running out of memory

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

Answers (2)

JCodes13
JCodes13

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

Don
Don

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

Related Questions