Activity 崩溃生命周期方法 - android

2022-01-12 00:00:00 backup crash android java android-activity

我正在开发一个应用程序,它在崩溃的情况下需要在崩溃时保存一些数据.现在,我将数据保存在 onDestroy() 中,如下所示:

I'm developing an app which in a case of crash, needs to save some data with the time of the crash. Now, I'm saving the data in onDestroy() like this:

@Override
protected void onDestroy() {
    saveState();
    super.onDestroy();
}

但每当我故意让我的应用程序崩溃时,不会调用 onDestroy() 并且不会保存我的数据.

But whenever I crash my app on purpose, onDestroy() is not called and my data is not saved.

我的问题是,如何在崩溃时保存我的数据?我应该采取哪种方法?因为我还需要保存崩溃的时间,所以这是强制性的.

My question is, how can I save my data on a crash? Which approach should I take? Because I need the time of the crash to be also saved, it's mandatory.

推荐答案

UncaughtExceptionHandler 非常适合捕获崩溃.

相关文章