Android应用程序组件销毁和重新创建的详细信息 [英] details of Android application components destruction and recreation

查看:188
本文介绍了Android应用程序组件销毁和重新创建的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我推些有关以下方面的具体,可信赖(最好是简明扼要)的信息的方向:

Could someone push me in the direction of some concrete, trustworthy (and preferably concise) information on the following:

  1. 系统销毁和重新创建组件的顺序 (片段,活动,活动的线程/AsyncTasks/计时器, 静态数据(何时卸载类?),其他类中的线程/AsyncTasks/Timer,主机 TabActivity,ActivityGroup,绑定的本地服务,应用程序,进程) 无论应用程序在后台还是在前台.
    在什么时候破坏可以停止(可以遇到什么状态 返回到应用程序后-类似于包括Application对象在内的所有内容 销毁了,还活着"?

  1. The order in which components are destroyed and (where applicable)recreated by the system (Fragment, Activity, Activity's Threads/AsyncTasks/Timers, static data(when are classes unloaded?), Threads/AsyncTasks/Timers in other classes, host TabActivity, ActivityGroup, bound local Services, Application, process) both when the app is in the background, and in the foreground.
    At which points the destruction can stop (what states can be encountered upon return to the app - like "everything including the Application object destroyed, process alive"?

是否有可能(无需修改Android)以编程方式导致相同的破坏

Is it possible (without modifying Android) to programmatically cause the same kind of destruction ourselves, so that it is indistinguishable from when the system does it, or is a separate mechanism needed for when we ourselves choose to free memory (triggered by onLowMemory)?

从1开始的所有场景的可靠再现步骤(junit.framework可以吗?我没有对此进行调查)?

Reliable reproduction steps of all scenarios from 1) (would junit.framework do? I haven't investigated that) ?

"如果用户长时间离开任务时间,系统会清除除根活动以外的所有活动的任务.当用户再次返回该任务时,仅恢复根活动:除了流程/组件生命周期/销毁之外还是捆绑在一起对吗?

"If the user leaves a task for a long time, the system clears the task of all activities except the root activity. When the user returns to the task again, only the root activity is restored": is this aside from the process/component lifecycle/destruction, or tied to it?

我阅读过各种资料来源,提供的信息往往不完整且具有误导性,有时甚至是不正确的.
我承认,我已经浏览了文档的某些部分,所以我可能错过或误解了某些内容.

为避免误解:我要问的是Android破坏组件以释放内存,绕过 Activity.onDestroy.
当我将应用置于后台并稍后返回时,将发生以下序列之一:

I have read various sources give pieces of information, often incomplete and misleading, sometimes incorrect.
I admit, I have skimmed over some parts of the documentation, so i may have missed or misunderstood something.

To avoid misunderstandings: What I am asking about is Android destroying components to free memory, bypassing Activity.onDestroy.
When I put the app in the background and return later, the one of these sequences will occur:

  • onPause,onStop,onRestart,onStart,onResume
  • onPause,onStop,Application.onCreate,onCreate(notNull),onStart,onResume

赏金开始.需要有关以下方面的可靠信息:活动,片段,应用程序,绑定的(可能是远程的)服务,流程.
部分/全部销毁方案.见第一点.

Bounty started. Need reliable info on: Activities, Fragments, Application, bound (potentially remote)Services, process.
Partial/full destruction scenarios. See 1st point.

推荐答案

为此,贷方 hackbod 进行了编写此处(阅读完整答案),并链接到 CommonsWare 以链接到评论.

简而言之:多次重写的所有文档骗我们他们没有误导,只是给了我们不真实的信息.除非您使用的是Fragments(如果也支持v4,也不知道),Android会通过杀死整个过程来释放内存,否则什么也不做.

当然,这不能解决所有问题:

Credit for this goes to hackbod for writing it here(read the whole answer), and to CommonsWare for linking in a comment.

In short: All the docs, rewritten many times, continue to lie to us. They're not misleading, they just give us untrue information. Unless you're using Fragments (dunno if support v4 counts, too), Android frees memory by killing the whole process, or does nothing.

Of course, this does not address everything:

  • 问题的第4点
  • 为什么我经常在Activity堆栈上按Back返回时经常看到onCreate(notNull),而Activity会处理所有配置更改(Android 2.3.7)
  • 这与广为接受的信念有关,即onPause是您肯定会接到的最后一个电话,而onStop可能永远不会被调用(那么,该应用程序如何才能进入后台被杀死?)

不过,我们到了某个地方.

We're getting somewhere, though.

这篇关于Android应用程序组件销毁和重新创建的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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