现在的位置: 首页 > 综合 > 正文

android报错后,如果友好提示

2013年09月09日 ⁄ 综合 ⁄ 共 1058字 ⁄ 字号 评论关闭
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方法注册

抱歉!评论已关闭.