我想捕获未捕获的异常并将有关它们的报告发送到我的服务器。这就是我实现它的方式:
public final class MyApplication extends Application
{
private static Context context;
private static Handler mainHandler;
private static boolean isDebug;
@Override
public void onCreate()
{
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler()
{
@Override
public void uncaughtException(final Thread thread, final Throwable ex)
{
new Thread()
{
@Override
public void run()
{
Looper.prepare();
ReportUtils.sendReport(thread, ex);
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(thread, ex);
Looper.loop();
Looper.myLooper().quit();
}
}.start();
}
});
context = getApplicationContext();
mainHandler = new Handler();
isDebug = (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));
}
@Override
public void onTerminate(){}
public static Context getAppContext()
{
return context;
}
public static boolean isDebugMode()
{
return isDebug;
}
public static Handler getMainHandler()
{
return mainHandler;
}
}
它是实施它的正确方法吗?还有其他选择吗?