onStop与onDestroy [英] onStop vs onDestroy

查看:105
本文介绍了onStop与onDestroy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试确切地研究过何时调用onDestroy方法来进行活动,但是我已经阅读了一些令人困惑和矛盾的信息.通常,我的问题是:在什么情况下onDestroy方法实际上是在活动上调用的?更具体地说,如果我有两个活动,即活动A和活动B,如果活动A正在运行并且我创建了一个意图并切换到活动B,则活动A仅停止还是被销毁?

I have tried to research exactly when the onDestroy method is called for an activity, but I've read some confusing and conflicting information. In general, my question is: under what circumstances is the onDestroy method actually called on an activity? More specifically, if I have two activities, activity A and activity B, if activity A is running and I create an intent and switch to activity B, is activity A only stopped, or is it destroyed?

推荐答案

类似于官方 在活动被销毁之前收到的最后一次呼叫.之所以会发生这种情况,可能是因为该活动即将结束(有人称其为finish(),或者是因为该系统正在临时销毁该活动的该实例以节省空间.您可以使用isFinishing()方法来区分这两种情况.

在您的示例中,活动A已停止,并且可能被系统破坏


每个上方documentation链接注意:

In your example the Activity A is stopped and could be destroyed by the System


Note per documentation link above:

…不要指望[onDestroy()]被称为保存数据的地方……[请参见onPause()onSaveInstanceState(Bundle).
…do not count on [onDestroy()] being called as a place for saving data … [see] either onPause() or onSaveInstanceState(Bundle).

这篇关于onStop与onDestroy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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