Android学习笔记:Activity生命周期详解
进行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生命周期详解的更多相关文章
- android学习笔记 activity生命周期&任务栈&activity启动模式
activity生命周期 完整生命周期 oncreate->onstart->onresume->onpause->onstop->ondestory 使用场景:应用程序 ...
- Android Activity 生命周期详解
学习android开发这么久对于activity的生命周期还没有仔细思考过,所以,我大致的把这些东西整理一下,希望通过这使自己理解的更透彻点吧! 首先看一下Activity生命周期图和它的的四个阶段 ...
- xamarin Android activity生命周期详解
学Xamarin我为什么要写这样一篇关于Android 的activity生命周期的文章 已经学Xamarin android有一段时间了,现在想起当初Xamarin也走了不少的弯路.当然Xamari ...
- Android关于Activity生命周期详解
子曰:溫故而知新,可以為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就完全掌握,那基本不大可能,所以我们需要经常回过头再仔细研读几遍,以领悟到作者的思想精 ...
- Android之Activity生命周期详解
Activity的生命周期方法: onCreate()--->onStart()--->onResume()--->onPause()--->onStop()--->on ...
- 【转】Activity生命周期详解
三个循环 提供两个关于Activity的生命周期模型图示帮助理解: 图1 图2 从图2所示的Activity生命周期 ...
- Android四大组件之---activity生命周期详解
废话不多说, 先来一张Google提供的一张经典的生命周期流程图: 有的朋友可能看英文的有点费劲,再提供一张中文版的 O(∩_∩)O 相信已经很多人对这张图再熟悉不过了,下面笔者按照自己的理解并结合 ...
- Activity生命周期详解
http://blog.csdn.net/liuhe688/article/details/6733407 onPause 回到 onResume 的过程“在一般的开发中用不上”,但是作为开发者还是有 ...
- Android学习笔记_18_Activity生命周期 及 跳转方式
一.Activity有三个状态: 1.当它在屏幕前台时(位于当前任务堆栈的顶部),它是激活或运行状态.它就是响应用户操作的Activity. 2. 当它上面有另外一个Activity,使它失去了焦点但 ...
随机推荐
- 第一篇:GCD多线程的概念
1.什么叫GCD? 简单来说就是:Grand Central Dispatch的简称,中文翻译就是:”牛逼的中枢调度器“ 这是纯C语言,还提供了非常多强大的函数 2.GCD的相对优势: (1)GCD是 ...
- Opencv 完美配置攻略 2014 (Win8.1 + Opencv 2.4.8 + VS 2013)下
前面说了一些在OpenCV在VS2013下的配置的过程,下面说一下其中的个别的知识点,了解一下这样配置的一点点更细节的过程.其实配置项目属性的时候,有两种方式: 一.通过项目属性管理器配置项目属性表 ...
- Linux下Apache服务器并发优化
Linux/UnixLinux系统下Apache 并发数的优化 Apache Http服务器采用prefork或者是worker两种并发控制模式. preforkMPM 使用多个子进程,每个子进程只 ...
- UltraEdit中java代码换行问题
在很多开发中始用的文本编辑器中UltraEdit是非常主流的种了,但是,随着版本的更新,最近几版中出现了以下问题 问题描述:当用UltraEd(14.0版本)编写Java代码时,当遇到{}换行时,希望 ...
- Sort list by merge sort
使用归并排序对链表进行排序 O(nlgn) 的时间效率 /** * Definition for singly-linked list. * struct ListNode { * int val; ...
- glib 文档 代码 索引 编译
./configure --prefix=/opt/glib-2.28.8 --enable-staticmakemake install linux下载 WIN32下载 代码索引 文档索引 GLib ...
- 【转】NP-Hard和NP-Complete的区别
原文来自:http://hi.baidu.com/nuclearspace/item/e0f8a1b777914974254b09f4 对 NP-Hard问题和NP-Complete问题的一个直观的理 ...
- chrome developer tool 调试技巧2
我大概是从 08.09 年从 Firebug 转入 Chrome Developer Tool,一直用到现在,越用越喜欢.我平时调错时常用的功能有: 代码格式化可以将被压缩的代码自动展开 实时代码编辑 ...
- Protel对话窗字体显示不完全问题解决办法(PCB)
点击protel99左上角的大箭头,点击preferences ,在对话框中把use client system fonts for all dialogs 复选框去掉,就可以了.
- 用200行Python代码“换脸”
介绍 本文将介绍如何编写一个只有200行的Python脚本,为两张肖像照上人物的“换脸”. 这个过程可分为四步: 检测面部标记. 旋转.缩放和转换第二张图像,使之与第一张图像相适应. 调整第二张图像的 ...