Activity 崩溃生命周期方法 - android [英] Activity crash lifecycle method - android

查看:78
本文介绍了Activity 崩溃生命周期方法 - android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,它在崩溃的情况下需要在崩溃时保存一些数据.现在,我将数据保存在 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 非常适合捕获崩溃.

这篇关于Activity 崩溃生命周期方法 - android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆