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,使它失去了焦点但 ...
随机推荐
- aop切入点表达式
1.切入点表达式:对指定的方法进行拦截,并且生成代理表达式. 2.拦截所有public方法 <aop:pointcut expression="execution(public * * ...
- SpringMVC 详解
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...
- Laravel 简单使用七牛云服务
前言 路漫漫其修远兮,吾将上下而求索.学习 Laravel 之初觉得所有东西都很厉害的样子,现在看来就是很厉害啊!最近在写一个项目上传的模块,要上传图片到七牛云,昨天看了一下午七牛云官方的文档感觉还是 ...
- r语言之条件、循环语句
if条件语句:if (conditon) {expr1} else {expr2} > x<-1> if(x==1)+ {x<-"x=1"}else+ {x ...
- [lua]笔试-按字典序列出指指定的序列的位置
计算方法: n的阶乘记为f(n), s为输入序列, sub(i)为s的i到n的子序列.A(i)为第i位对应的字母在子序列sub(i)中的字典顺序 N(s) = sum_{1,n} T(i)*(A(i) ...
- MySQL root密码重置报错:mysqladmin: connect to server at 'localhost' failed的解决方案!
-- ==================================================================== -- mysqladmin: connect to s ...
- Handler总结
一.整体工程图 二.activity_handler.xml <?xml version="1.0" encoding="utf-8"?> < ...
- android-改进<<仿QQ>>框架源代码
该文章主要改动于CSDN某大神的一篇文章,本人认为这篇文章的面向对象非常透彻,以下分享例如以下可学习的几点: Android应用经典主界面框架之中的一个:仿QQ (使用Fragment, 附源代码) ...
- eclipse svn2.0.0插件 手动安装方法
org.tigris.subversion.javahl.ClientException: Unsupported working copy formatsvn: This client is too ...
- 瑞星杀毒软件、奇虎360杀毒软件、360卫士、百度卫士联手,搞不定弹出广告 & 恶意广告图标
一位网友说他的电脑近期出了问题:开机后桌面和任务栏上的高速启动栏会出现恶意图标.删除了下次开机又会出现:使用电脑过程中每分钟都会弹出广告.他为电脑安装了瑞星杀毒软件.奇虎360杀毒软件.360卫士.百 ...