Android程序异常崩溃处理
2015-03-02 14:25
513 查看
Thread.UncaughtExceptionHandler类用于处理程序未捕获的异常,当程序发生运行时异常就会进入该类的uncaughtException方法进行处理
public class CrashHandler implements Thread.UncaughtExceptionHandler { public static final String TAG = "CrashHandler"; private static CrashHandler INSTANCE = new CrashHandler(); private Context mContext; private Thread.UncaughtExceptionHandler mDefaultHandler; private CrashHandler() { } public static CrashHandler getInstance() { return INSTANCE; } public void init(Context ctx) { mContext = ctx; mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); } @Override public void uncaughtException(Thread thread, Throwable ex) { System.out.println("异常出现"); // ex.printStackTrace(); Intent _intent = new Intent(mContext, LoginActivity.class); _intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(_intent); android.os.Process.killProcess(android.os.Process.myPid()); } }
相关文章推荐
- Android:处理程序崩溃异常
- Android程序崩溃异常处理框架
- android 中处理崩溃异常并重启程序
- Android程序崩溃异常处理框架
- android在程序崩溃时Catch异常并处理
- [置顶] Android程序崩溃异常处理之自动发送邮件
- Android全局异常处理(捕获异常,不弹出程序崩溃)
- android处理crash程序崩溃异常
- (4.1.35.1) android处理crash程序崩溃异常
- android 中处理崩溃异常并重启程序
- android 中处理崩溃异常并重启程序
- Android全局异常处理(捕获异常,不弹出程序崩溃)
- android 中处理崩溃异常并重启程序出现页面重叠的问题
- android处理crash程序崩溃异常
- android 中处理崩溃异常并重启程序
- Android:处理程序崩溃异常
- Android:处理程序崩溃异常
- android 中处理崩溃异常并重启程序出现页面重叠的问题
- Android全局异常处理(捕获异常,不弹出程序崩溃)
- android 中处理崩溃异常并重启程序