如何活动概况由系统杀死 [英] Overview of how Activities are killed by the system

查看:171
本文介绍了如何活动概况由系统杀死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给的情况下,何时以及如何活动由运行时杀了一个简短的概述?我想知道的暂停和停止状态之间的差异。有什么能强制系统摧毁暂停活动,如出一辙(内存不足)的原因,如果它被停止?

Can anyone give a short overview of the cases when and how an activity is killed by the runtime? I'd like to know the difference between the paused and stopped state. What could force the system to destroy a paused activity, exactly the same (low memory) reason as if it was stopped?

我想,如果一个活动,是因为呼入电话(这突然导致内存不足的情况​​),该系统只需prefers释放停止活动ressources的暂停。但如何做呢?什么时候系统恳请活动,通过调用完成(),如果没有,确实的onDestroy(时),仍然可以叫什么名字?

I think if an activity is paused because of an incoming phone call (which suddenly causes a low memory situation) the system simply prefers to release ressources of stopped activities. But how is that done? When does the system "kindly ask" the activity by calling finish() and when not, and when does onDestroy() still get called?

推荐答案

大多数时候,你问什么是文档描述pretty好,但我想我可以澄清一些事情。

Most of what you asked is described pretty well by the documentation, but I think I can clarify a couple of things.

我想知道其中的差别
  暂停和停止状态之间。

I'd like to know the difference between the paused and stopped state.

可见性。这两种状态是不同的,因为暂停活动可能只能部分地被另一个活动掩盖,如一个年代曾采用的对话框的主题。这就要求无论是需要资源来维持可视状态保持。停止活动可以抛弃这些资源,这可以使被破坏的活动或preserved之间的区别,如果资源紧张。

Visibility. The two states are distinct because a paused activity may only be partially obscured by another activity such as one that's had the Dialog theme applied. That requires keeping whatever resources are needed to maintain visual state. Stopped activities can jettison those resources which could make the difference between the activity being destroyed or preserved if resources are tight.

我觉得...系统只需prefers
  发布的停止ressources
  活动。但如何做呢?

I think ... the system simply prefers to release ressources of stopped activities. But how is that done?

它必须。停止活动是完全不可见的,这使得他们更好地为考生比那些仍然贡献一些东西到用户看到的查杀。我从来没有见过的Andr​​oid抽出一个暂停,但是,部分可见的活动出由根据的恢复,但我想它可能在正常情况下发生的。该系统知道每个活动的状态,因为它就是在那儿指挥他们。

It has to. Stopped activities are completely invisible, which makes them better candidates for killing than those that are still contributing something to what the user sees. I've never seen Android yank a paused-but-partially-visible activity out from under one that's resumed, but I suppose it could happen under the right circumstances. The system knows each activity's state because it's what's directing them there.

在做系统的恳请的
  通过调用完成活动(),当
  不,一点的onDestroy()时仍然
  被调用?

When does the system "kindly ask" the activity by calling finish() and when not, and when does onDestroy() still get called?

,系统将何时能做到有序的破坏,但是API唯一保证是一个活动永远不会看到的onPause()的onSaveInstanceState( )

The system will do orderly destruction when it can, but the API only guarantees are that an activity will ever see onPause() and onSaveInstanceState().

ETA:为什么活动是从堆栈中移除的确切原因是源。你不应该依赖于这些原因是放之四海而皆准的真理,因为可能存在的Andr​​oid的未来版本,使得它的决定是不同的。

ETA: The exact reasons why activities are removed from the stack are in the source. You shouldn't depend on those reasons being universal truth, because there may be a future version of Android that makes its decisions differently.

这篇关于如何活动概况由系统杀死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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