問題描述
我正在開發(fā)一個(gè)應(yīng)用程序,它在崩潰的情況下需要在崩潰時(shí)保存一些數(shù)據(jù).現(xiàn)在,我將數(shù)據(jù)保存在 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();
}
但每當(dāng)我故意讓我的應(yīng)用程序崩潰時(shí),不會調(diào)用 onDestroy() 并且不會保存我的數(shù)據(jù).
But whenever I crash my app on purpose, onDestroy() is not called and my data is not saved.
我的問題是,如何在崩潰時(shí)保存我的數(shù)據(jù)?我應(yīng)該采取哪種方法?因?yàn)槲疫€需要保存崩潰的時(shí)間,所以這是強(qiáng)制性的.
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 非常適合捕獲崩潰.
這篇關(guān)于Activity 崩潰生命周期方法 - android的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!