Actiivity 生命周期
Actiivity 生命周期,如下图所示: onCreate onStart (onRestarted) onResume onPaused(to onResume(User navigates to the activity)) onStop onDestroy

onCreate 方法: 一定要实现OnCreate方法,初始化 组件和布局。
onPause 方法:用户离开activity是的第一个被触发的方法。
onDestroy 方法: 系统也许直接kill了process,这个方法未必会被调用。
An activity can exist in essentially three states:
- Resumed
- The activity is in the foreground of the screen and has user focus. (This state is also sometimes referred to as "running".)
- Paused
- Another activity is in the foreground and has focus, but this one is still visible. That is, another activity is visible on top of this one and that activity is partially transparent or doesn't cover the entire screen. A paused activity is completely alive (the
Activityobject is retained in memory, it maintains all state and member information, and remains attached to the window manager), but can be killed by the system in extremely low memory situations. - Stopped
- The activity is completely obscured by another activity (the activity is now in the "background"). A stopped activity is also still alive (the
Activityobject is retained in memory, it maintains all state and member information, but is not attached to the window manager). However, it is no longer visible to the user and it can be killed by the system when memory is needed elsewhere.
两个Activity跳转时的生命周期方法调用顺序, 例如 Activity A 跳转到 Activity B:
- Activity A's
onPause()method executes. //先执行A的onPause方法 - Activity B's
onCreate(),onStart(), andonResume()methods execute in sequence. (Activity B now has user focus.) //Activity B's onCreate、onStart、onResume方法 - Then, if Activity A is no longer visible on screen, its
onStop()method executes. // 执行A的onStop方法
综上,如果有数据交换、交互,请在A的onPause里面执行,否则B启动了也找不到新数据。
Actiivity 生命周期的更多相关文章
- react组件的生命周期
写在前面: 阅读了多遍文章之后,自己总结了一个.一遍加强记忆,和日后回顾. 一.实例化(初始化) var Button = React.createClass({ getInitialState: f ...
- 浅谈 Fragment 生命周期
版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Fragment 文中如有纰漏,欢迎大家留言指出. Fragment 是在 Android 3.0 中 ...
- C# MVC 5 - 生命周期(应用程序生命周期&请求生命周期)
本文是根据网上的文章总结的. 1.介绍 本文讨论ASP.Net MVC框架MVC的请求生命周期. MVC有两个生命周期,一为应用程序生命周期,二为请求生命周期. 2.应用程序生命周期 应用程序生命周期 ...
- UIViewController生命周期-完整版
一.UIViewController 的生命周期 下面带 (NSObject)的方法是NSObject提供的方法.其他的都是UIViewController 提供的方法. load (NSObje ...
- angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
- Spring中Bean的作用域、生命周期
Bean的作用域.生命周期 Bean的作用域 Spring 3中为Bean定义了5中作用域,分别为singleton(单例).protot ...
- Autofac - 生命周期
实例生命周期决定在同一个服务的每个请求的实例是如何共享的. 当请求一个服务的时候,Autofac会返回一个单例 (single instance作用域), 一个新的对象 (per lifetime作用 ...
- 【微信小程序开发•系列文章六】生命周期和路由
这篇文章理论的知识比较多一些,都是个人观点,描述有失妥当的地方希望读者指出. [微信小程序开发•系列文章一]入门 [微信小程序开发•系列文章二]视图层 [微信小程序开发•系列文章三]数据层 [微信小程 ...
- Xamarin.Android活动的生命周期
一.前言 用过Android手机的人一定会发现一种现象,当你把一个应用置于后台后,一段时间之后在打开就会发现应用重新打开了,但是之前的相关的数据却没有丢失.可以看出app的“生命”是掌握在系统手上的, ...
随机推荐
- svn update 时总是提示 Password for '默认密钥' GNOME keyring: 输入密码
执行svn update 时 总是提示输入密码. $ cd ~/.gnome2/keyrings/ $ ls $ rm 默认密钥.keyring
- mysql 全连接 报错1051的原因
由于mysql 不支持 直接写full outer join 或者 full join来表示全外连接但是可以用left right union right 代替 下面是例子: select * fro ...
- B4260 Codechef REBXOR
真是6块钱cpu(笑 爆炸入口 踹树练习(汗 对于二进制异或和弹性,我们可以贪心的来做. 瓶颈在于快速贪心. 我们可以维护一个trie树,储存异或前缀和.每次在trie树上贪心的跑. 正向and反向跑 ...
- Getting aCC Error :name followed by "::" must be a class or namespace name"
Getting aCC Error :name followed by "::" must be a class or namespace name" 原始是这样子的: ...
- js 动态创建标记
innerHTML:一旦使用了这个属性,它的全部内容都要被替换掉.且不会返回任何对刚插入的内容的引用 与document.write()方法一样,innerHTML属性也是HTML专有属性,不能用于任 ...
- 前端jQuery之动画操作及相关演示
1.显示动画 1.1无参数,直接让指定的元素显示出来 $("div").show(); 1.2通过控制宽高,透明度,display属性逐渐显示,指定时间现实完毕 $('div'). ...
- call()和apply()
每个函数都包含apply和call方法. 相同点:都接收两个参数,一个是在其中运行函数的作用域,另一个是参数: 不同点:call方法和apply的不同之处在于接收参数的方式不同: apply方法第二个 ...
- LeetCode94. Binary Tree Inorder Traversal
题目 给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 考点 stack ...
- IDEA的使用方法(二)(代码提示)
工欲善其事必先利其器: 在eclipse用久了代码提示对自己纯手搓代码还是不太好的,我就算是死,从楼上跳下去,也不会从了IDEA的代码提示的,在手搓了一个hello world之后,我写的是JAVA? ...
- linux下Tomcat配置提示权限不够解决办法
在终端输入命令 sudo chmod -R 777 /opt/Tomcat,那么Tomcat文件夹和它下面的所有子文件夹的属性都变成了777(读/写/执行权限)