package com.nhn.android.exception; import java.io.File; import java.io.PrintWriter; import java.lang.Thread.UncaughtExceptionHandler; import android.content.Context; import com.nhn.android.util.Global; public class CndicExceptionHandler implements UncaughtExceptionHandler { private static CndicExceptionHandler handler; private static Context mContext; public static CndicExceptionHandler getInstence(Context cont){ mContext=cont; if(handler==null){ handler=new CndicExceptionHandler(); } Thread.setDefaultUncaughtExceptionHandler(handler); return handler; } @Override public void uncaughtException(Thread thread, Throwable ex) { // Intent intent = new Intent(mContext, WelcomeActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // mContext.startActivity(intent); // // android.os.Process.killProcess(android.os.Process.myPid()); try{ File file=new File(Global.SD_ROOT+Global.DOWN_PATH+File.separator+Global.ERROR_LOG); if(!file.exists()){ file.createNewFile(); } PrintWriter pw=new PrintWriter(file); ex.printStackTrace(pw); pw.close(); }catch(Exception exception){ } ex.printStackTrace(); } }
activity里调用getInstence方法注册