android报错后,如果友好提示

来源:互联网 发布:知柏地黄丸吃多久 编辑:程序博客网 时间:2024/05/21 11:10
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;}@Overridepublic 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方法注册
原创粉丝点击