可以仅通过onPause杀死一项活动吗? [英] Can an activity be killed with just onPause?

查看:78
本文介绍了可以仅通过onPause杀死一项活动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我从书中读到的:

onPause()之后,活动可以被静默破坏.我们绝不应该假设调用了onStop()或onDestroy().

The activity can be destroyed silently after onPause(). We should never assume that either onStop() or onDestroy() is called.

但是根据文档,暂停是指部分可见,是否可以在不调用onStop或onDestory的情况下杀死部分可见的活动?

But according to the documentation, Pause refers to partly visible, can an activity partly visible be killed without calling onStop or onDestory?

推荐答案

不能保证将调用onStoponDestroy.在严重缺乏内存的情况下,可能会破坏部分可见且无法聚焦的Activity以回收资源.但是,不能保证在执行此操作之前将调用上述两个生命周期方法中的任何一个.这就是为什么将持久状态保存在onPause中而不是onStoponDestroy中的原因.

There is no guarantee that onStop or onDestroy will be called. In situations when memory is severely lacking, the partially visible and out-of-focus Activity may be destroyed to reclaim resources. However, there is no guarantee that either of the two mentioned lifecycle methods will be called before doing so. This is why it is important to save persistent state in onPause instead of onStop and onDestroy.

这篇关于可以仅通过onPause杀死一项活动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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