gpt4 book ai didi

android - 意外的 android 应用程序终止而没有崩溃异常

转载 作者:太空狗 更新时间:2023-10-29 14:46:47 25 4
gpt4 key购买 nike

我使用以下代码在出现任何未处理的异常时自动重新启动我的应用程序。

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);
}
};

在 Activity onCreate 中:

Thread.setDefaultUncaughtExceptionHandler(onCrashRestart);

这按预期工作。但是,我亲眼目睹了我的应用程序在没有到达此处理程序的情况下被杀死的情况。我在日志中也看不到任何崩溃异常,我正在设备的 sdcard 中维护。

在尝试了多次 hack 之后,我停止了应用程序中的所有 sqlite 数据库操作,此意外崩溃从此停止。

我的问题是,是否存在任何已知的情况,其中 android 终止了应用程序并且在崩溃时没有给出任何异常?

另外,android 在什么情况下会在前台运行时杀死应用程序?

编辑:我在我的应用程序中使用 Renderscript api 进行位图操作。在模拟器中运行时,出现以下错误:

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
....

这会是罪魁祸首吗?

最佳答案

应用程序如果在 native 代码中崩溃,Java 异常不适用。在一个这样的实例中使用 Renderscript 支持库。通常,这些很难调试。

阅读 - Catching exceptions thrown from native code running on Android关于处理相同的问题。

关于android - 意外的 android 应用程序终止而没有崩溃异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39278309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com