进行android的开发,必须深入了解Activity的生命周期。而对这个讲述最权威、最好的莫过于google的开发文档了。

本文的讲述主要是对 http://developer.android.com/training/basics/activity-lifecycle/index.html 的翻译,加上了个人的一些细节和补充。

一、概述

Managing the Activity Lifecycle

管理Activity的生命周期

As a user navigates through, out of, and back to your app, the Activity instances in your app transition between different states in their lifecycle.

当用户进入、离开和返回一个app程序时,程序中的Activity实例会在它们的生命周期中的各个状态之间切换。

For instance, when your activity starts for the first time, it comes to the foreground of the system and receives user focus.

比如,当第一次启动Activity时,它会处于系统的前台,并且能接受用户的操作聚焦。

During this process, the Android system calls a series of lifecycle methods on the activity in which you set up the user interface and other components.

在这个过程中,android系统会调用Activity的一系列生命周期会调方法,从而创建用户界面和其它的组件。

If the user performs an action that starts another activity or switches to another app, the system calls another set of lifecycle methods on your activity as it moves into the background (where the activity is no longer visible, but the instance and its state remains intact).

当用户执行动作启动另外一个Activity或切换到另外一个app时,该Activity,会移到系统后台(这时Activity将不再可视,但它的实例和状态将原封不动的保存着),这时系统将会调用该Activity 的另外一系列生命周期会调方法,

Within the lifecycle callback methods, you can declare how your activity behaves when the user leaves and re-enters the activity.

在Activity的生命周期会调方法内,你可以定义当用户离开和重新进入Activity时,你想要做的事情。

For example, if you're building a streaming video player, you might pause the video and terminate the network connection when the user switches to another app.

比如,如果你在编写一个实时流视频播放程序,在视频正在播放时,用户切换到另外一个app(如用户按home键、电话来了等),这时程序要能够暂停视频播放,并且断开网络链接。

When the user returns, you can reconnect to the network and allow the user to resume the video from the same spot.

当用户重新返回到该视频播放程序,程序应该能够恢复网络链接,并且从前面停止的点开始继续恢复视频播放。

This class explains important lifecycle callback methods that each Activity instance receives and how you can use them so your activity does what the user expects and does not consume system resources when your activity doesn't need them.

本课程将会将会介绍Activity的每个重要的生命周期回调方法,并且告诉你如何处理,从而处理的结果与用户期望保持一致。而且当Activity不再需要时,能不让其继续耗费系统资源。

二、Starting an Activity

启动Activity

Unlike other programming paradigms in which apps are launched with a main() method, the Android system initiates code in an Activity instance by invoking specific callback methods that correspond to specific stages of its lifecycle.

很多其它的编程语言程序从main方法开始运行,而Android程序不同,Android系统通过回调Activity特定的生命周期方法来实例化一个Activity,并且根据其位于不同的生命周期作出不同的反应。

There is a sequence of callback methods that start up an activity and a sequence of callback methods that tear down an activity.

当启动一个Activity时,会触发一系列的回调方法;同样,当关闭一个Activity时,也会触发一系列的回调方法。

This lesson provides an overview of the most important lifecycle methods and shows you how to handle the first lifecycle callback that creates a new instance of your activity.

本小结将会大致的介绍下Activity的各个重要的生命周期方法,并且通过处理第一个生命周期方法来实例化一个Activity。

Android学习笔记:Activity生命周期详解的更多相关文章

  1. android学习笔记 activity生命周期&任务栈&activity启动模式

    activity生命周期 完整生命周期 oncreate->onstart->onresume->onpause->onstop->ondestory 使用场景:应用程序 ...

  2. Android Activity 生命周期详解

    学习android开发这么久对于activity的生命周期还没有仔细思考过,所以,我大致的把这些东西整理一下,希望通过这使自己理解的更透彻点吧! 首先看一下Activity生命周期图和它的的四个阶段 ...

  3. xamarin Android activity生命周期详解

    学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...

  4. Android关于Activity生命周期详解

    子曰:溫故而知新,可以為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就完全掌握,那基本不大可能,所以我们需要经常回过头再仔细研读几遍,以领悟到作者的思想精 ...

  5. Android之Activity生命周期详解

    Activity的生命周期方法: onCreate()--->onStart()--->onResume()--->onPause()--->onStop()--->on ...

  6. 【转】Activity生命周期详解

    三个循环 提供两个关于Activity的生命周期模型图示帮助理解:                                           图1 图2 从图2所示的Activity生命周期 ...

  7. Android四大组件之---activity生命周期详解

    废话不多说, 先来一张Google提供的一张经典的生命周期流程图: 有的朋友可能看英文的有点费劲,再提供一张中文版的  O(∩_∩)O 相信已经很多人对这张图再熟悉不过了,下面笔者按照自己的理解并结合 ...

  8. Activity生命周期详解

    http://blog.csdn.net/liuhe688/article/details/6733407 onPause 回到 onResume 的过程“在一般的开发中用不上”,但是作为开发者还是有 ...

  9. Android学习笔记_18_Activity生命周期 及 跳转方式

    一.Activity有三个状态: 1.当它在屏幕前台时(位于当前任务堆栈的顶部),它是激活或运行状态.它就是响应用户操作的Activity. 2. 当它上面有另外一个Activity,使它失去了焦点但 ...

随机推荐

  1. Compare the value of entity field.

    public class Program { static void Main(string[] args) { Program p = new Program(); p.Test(); Consol ...

  2. CSS的display、hover、overflow、&copy(版权符号)、borer-radius(边框圆角)

    一.display: none 隐藏 block显示     visibility:hidden隐藏 visible显示 display:none和visibility:hidden这两个属性对应的值 ...

  3. [译]Stairway to Integration Services Level 8 - SSIS 工作流管理高级

    介绍 在前两个章节我们,建立了一个新的SSIS包,简单的使用了一下scripting还有优先约束,并且测试了MaxConcurrentExecutables 属性.  同时实验了  “On Succe ...

  4. 【ActiveMQ】设置自动重连

    <property name="brokerURL" value="tcp://localhost:61616"/> <property na ...

  5. hibernate的常用配置

    hibernate.cfg.xml的一些相关配置 <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Co ...

  6. BZOJ 1863: [Zjoi2006]trouble 皇帝的烦恼( 二分答案 )

    二分答案..然后从头到尾推一下, 看最后一个能不能取0个和第一个人相同的勋章 ------------------------------------------------------------- ...

  7. Android的回调模拟

    想要彻底理解安卓中用的回调,最好的办法是自己写一个类似的实现安卓中回调功能的实现方法. 我自己写了一个可以实现setOnClickListener回调的工程: 具体目录: 工程源码的具体地址:http ...

  8. Yii框架中的CURD操作

    <?php $Admin = new Admin(); //查找多条记录,返回二维数组 $Admin->findAll(); $Admin->findAll("id = 2 ...

  9. Arcengine 开发,FeatureClass新增feature时“The Geometry has no z-value”或"The Geometry has null z-value"的解决方案

    Arcengine 开发,当图层含有Z值时,新增的feature没有Z值就会 出现“The Geometry has no z-value”的错误.意思很明显,新增的geometry没有Z值. 此时按 ...

  10. 浅谈Linux ftp服务器相关配置

    首先我们需要在Linux系统下安装FTP服务器  Ubuntu sudo apt-get install.......  centos yun....... 然后,我们要配置vsftpd.conf文件 ...