Today see Thunder Anime inside a Crashhandler class, I guess is the crash processing class. In a look, sure enough. Learn by the way.
The "program exception exit" of the Android system adversely affects the user experience of the app. To capture application run-time exceptions and give friendly hints, you can inherit the Uncaughtexceptionhandler class to handle. The exception-handling class is set to the thread by using the Thread.setdefaultuncaughtexceptionhandler () method.
Code:
public class Crashhandler implements Uncaughtexceptionhandler {private static final Logger LOG = Logger.getlogger (Cras Hhandler.class); Private final application mapplication; Private Handler Muihandler; Private Thread Muithread; Public Crashhandler (Application app) {mapplication = app; Muihandler = new Handler (); Muithread = Thread.CurrentThread (); } @Override public void uncaughtexception (thread thread, Throwable e) {log.error (e); Throwable cause = E.getcause (); while (cause! = null) {Log.error (cause); Cause = Cause.getcause (); } writecrashinfotofile (e); if (Thread.CurrentThread ()! = Muithread) {muihandler.post (new Runnable () {@Override public void Run () {mapplication.onterminate (); } }); } else {mapplication.onterminate (); }} private void WritecrashinfoToFile (Throwable t) {stringwriter SW = new StringWriter (); PrintWriter pw = new PrintWriter (SW); T.printstacktrace (PW); Throwable cause = T.getcause (); while (cause! = null) {cause.printstacktrace (PW); Cause = Cause.getcause (); } String CrashInfo = Sw.tostring (); Pw.close (); try {if (Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {File File = Mapplication.getapplicationcontext (). Getexternalcachedir (); if (file = null) {file = Fileutils.getfile (file, "Crash"); File.mkdirs (); Fileutils.writestringtofile (fileutils.getfile (file, "Crash.log"), CrashInfo); }}} catch (IOException e) {Log.warn (e); } }}Two references that can be seen:
Http://blog.csdn.net/hehe9737/article/details/7662123
http://blog.csdn.net/wangbole/article/details/8161524
Code is their own, although simple, I am the original bar. Otherwise, it's really hard to put on the force.
Android Capture program exits unexpectedly