Skip to content

Instantly share code, notes, and snippets.

@ej3
Created November 7, 2014 00:04
Show Gist options
  • Save ej3/30759459209f1bd118a3 to your computer and use it in GitHub Desktop.
Save ej3/30759459209f1bd118a3 to your computer and use it in GitHub Desktop.
add top level execution handler to try to create heap dump on OutOfMemoryError
public class MyActivity extends Activity {
public static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e("UncaughtException", "Got an uncaught exception: "+ex.toString());
if(ex.getClass().equals(OutOfMemoryError.class))
{
try {
android.os.Debug.dumpHprofData("/sdcard/dump.hprof");
} catch (IOException e) {
e.printStackTrace();
}
}
ex.printStackTrace();
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment