002.android生命周期(Activity Liftcycle)

    为了文档的正规与方便性,我把一些有关的API文档的内容也粘贴进来了,虽然是英文的,但是还是比较好理解的,同时,我也把它翻译成中文了,方便大家对比使用。

    android的生命周期我想是所有老师讲课的第一课吧。以前,我一直在想,我为什么要知道生命周期,我不知道它,可是我依旧可以写程序啊,为什么人们把生命周期看的这么重要。

      其实,一个完整的程序,从它的出现到结束,就是一次生命。当你再开启的时候,似乎生命有进行了一场轮回。有没有一点感觉,我们好像可以主宰者一个生命。我想首先我们要先了解一下什么是生命周期。

    顾名思义:生命周期:一个程序从创建到消亡的过程。官方是这么说的:

     Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity -- the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.

我来翻译一下:在系统中的activity是被一个activity的堆栈管理的。当一个新的activity启动的时候,这个activity就会被安置在堆栈的顶层,此时它的状态是“运行时状态”

而,先前的activity就会被放在新启动的那个activity的地下,此时,这个activity绝不会在到堆栈的顶层,除非新启的activity退出。

An activity has essentially four states:

一个activity有四种状态:

  • If an activity in the foreground of the screen (at the top of the stack), it is active or running.

如果一个activity至于当前屏幕所见,则其为运行状态、

  • If an activity has lost focus but is still visible (that is, a new non-full-sized or transparent activity has focus on top of your activity), it is paused. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.

如果一个activity失去焦点但是可见,其为暂停状态。

  • If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.

如果一个activity完全被另一个activity覆盖了,则这个activity出于停止状态。

  • If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.

如果一个activity出于暂停或停止状态,我们可以通过finish方法从内存中将activity停掉。进入终止状态。

 

The following diagram shows the important state paths of an Activity. The square rectangles represent callback methods you can implement to perform operations when the Activity moves between states. The colored ovals are major states the Activity can be in.

下面是一个activity的生命周期的过程。如图:

State diagram for an Android Activity Lifecycle.

 

详解:

一个新的activity的启动会经过以下几个过程:onCreate,onStart,onResume。

activity1启动activity2会经过:1onPause,2onCreate,2onStart,2onResume,1onStop。

 

转载于:https://my.oschina.net/cjkall/blog/195862

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值