Created
November 7, 2014 00:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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