The stack call log that causes the program to crash writes to the file for easy collection of bugs. In Debugging the Android program, for some reason the phone can not connect to the PC side, the IDE can not see the program crashed log, I hope log can be written to the file, for the published app can be used to collect bugs through this feature.
01import Java.io.filenotfoundexception;02import Java.io.fileoutputstream;03import Java.io.ioexception;04import Java.io.printstream;05import java.lang.thread.uncaughtexceptionhandler;06 07public class Mycrashhandler implements uncaughtexceptionhandler{08 private static Mycrashhandler crashhandler;10 @Override12 public void Uncau Ghtexception (thread thread, Throwable ex) {//TODO auto-generated method stub14 if (Crashhandler! = null) {try {vi template Daquan //write crash log to file &NB Sp fileoutputstream FileOutputStream = new FileOutputStream ("/mnt/sdcard/crash_log.txt", true); printstream printstream = new PrintStream (fileoutputstream), &NBS P ex.printstacktrace (printstream) &NBS P;printstream.flush () printstream.close (); &NBS P fileoutputstream.close (),   Filenotfou; Ndexception e) { //TODO auto-generated catch block25 &nbs P e.printstacktrace (), + } catch (Ioexcept Ion e) {   //TODO auto-generated catch block28 &N Bsp e.printstacktrace () }30 }31  }&NB sp;32 33 //Set default processor thread public void init () {+] . Setdefaultuncaughtexceptionhandler (this);  }HTTP://WWW.HUIYI8.COM/VI/37 38 private Mycrashhandler () {}39 40 //single-case, public static Mycrashhandler I Nstance () { if (Crashhandler = = null) {$ synchroniz Ed (crashhandler) { crashhandler = new Mycrashhandler (); }46 }47 return crashhandler;48 &N Bsp  }49}