如果出现任何未处理的异常,我将使用以下代码自动重新启动我的应用程序。
private Thread.UncaughtExceptionHandler onCrashRestart = new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable ex) {
LOGGER.error("Unhandled Runtime exception occured ", ex);
LOGGER.info("Restarting app in 5 seconds");
Intent crashedIntent = new Intent(getApplicationContext(), RegisterActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, crashedIntent, 0);
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 5000, pendingIntent);
System.exit(2);
}
};
在活动onCreate
中:
Thread.setDefaultUncaughtExceptionHandler(onCrashRestart);
这正如期而至。但是,我亲眼目睹了我的应用程序在没有找到这个处理程序的情况下被杀死的例子。我也无法在日志中看到任何崩溃异常,这是我在设备的sdcard中维护的。
在尝试了多个黑客之后,我停止了应用程序中的所有sqlite数据库操作,这个意外的崩溃已经停止了。
我的问题是,有任何已知的情况下,android杀死了应用程序,而这并没有给出任何例外的崩溃?
另外,在什么情况下,android会在前台运行时杀死应用程序?
编辑:我在我的应用程序中使用Renderscript apis进行位图操作。在模拟器中运行时,会出现以下错误:
09-01 15:04:46.866 4624-9767/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:04:46.878 4624-9758/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:04:46.882 4624-9610/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:04:46.914 4624-9758/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:04:46.934 4624-9781/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
....
这可能是罪魁祸首吗?
发布于 2016-09-06 06:21:12
应用程序如果在本机代码中崩溃,Java异常就不适用。在其中一个实例中使用Renderscript支持库。通常情况下,它们很难调试。
读- Catching exceptions thrown from native code running on Android关于处理同样的.
https://stackoverflow.com/questions/39278309
复制相似问题