进行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. 面试之get和post(转)

    总结1 表单提交中get和post方式的区别归纳如下几点: GET是从服务器上获取数据,POST是向服务器传送数据,GET 请求一般不应产生副作用.就是说,它仅仅是获取资源信息,就像数据库查询一样,不 ...

  2. BZOJ 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛( floyd )

    对于第 i 头牛 , 假如排名比它高和低的数位 n - 1 , 那么他的 rank 便可以确定 . floyd -------------------------------------------- ...

  3. JQuery隔行变色

    <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...

  4. (转)跟我一起写MAKEFILE

    概述 —— 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序员,makef ...

  5. (IOS)截图Demo

    思路是建一个UIView的子类,获取划动出的矩形,用协议将矩形传递给代理对象,依据该矩形完成图像数据的截取,并显示出来. 截图视图类: #import <UIKit/UIKit.h> @p ...

  6. How do I Find Out Linux CPU Utilization?

    From:http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html Whenever a Linux sys ...

  7. AutoCAD 2014简体中文版官方正式版x86 x64下载,带注册机,永久免费使用

    注册机使用说明:会有部分杀毒软件报病毒,请无视.操作步骤:1.安装Autodesk AutoCAD 20142.使用以下序列号666-69696969安装.3.产品密码为001F14.安装完成后,启动 ...

  8. html = data.decode('gbk').encode('utf-8')

    html = data.decode('gbk').encode('utf-8')此处encode编码要与html文件内charset=utf-8的格式一致,如果不一致,浏览器打开乱码,文本编辑器正常 ...

  9. HDU 4720 Naive and Silly Muggles (外切圆心)

    Naive and Silly Muggles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  10. BZOJ 1412: [ZJOI2009]狼和羊的故事( 最小割 )

    显然是最小割...把狼的领地连S, 羊的领地连T, 然后中间再连边, 跑最大流就OK了 -------------------------------------------------------- ...