activity中oncreate的参数的意义
2016-07-25 18:37
501 查看
一、一个参数:
这个参数配合以下两个方法使用
1.前一个在app切换到后台时调用,在onPause和onStop之间调用,调用finish结束activity时不会调用此方法(会调用onpause和onstop)
2.后一个只有系统结束了应用(而不是程序主动结束应用)然后再打开的时候才会调用,比如:
横竖屏切换
切换到后台,系统因为内存不足杀死进程,再次打开时
而自己主动结束应用,比如调用了finish,或者切换到后台再切换到前台
在调用onRestoreInstanceState的情况下,在onSaveInstanceState中保存到Bundle的数据会同时传给onCreate和onRestoreInstanceState,这就是onCeate参数中savedInstanceState的意义,如果不是在onRestoreInstanceState会调用的场景里,savedInstanceState为null
二、两个参数
对应
会对保存的信息做持久化(重启后还能访问)
此组方法调用时机不确定,一直没有模拟出来
protected void onCreate(Bundle savedInstanceState)
这个参数配合以下两个方法使用
protected void onSaveInstanceState(Bundle outState)
public void onRestoreInstanceState(Bundle savedInstanceState)
1.前一个在app切换到后台时调用,在onPause和onStop之间调用,调用finish结束activity时不会调用此方法(会调用onpause和onstop)
2.后一个只有系统结束了应用(而不是程序主动结束应用)然后再打开的时候才会调用,比如:
横竖屏切换
切换到后台,系统因为内存不足杀死进程,再次打开时
而自己主动结束应用,比如调用了finish,或者切换到后台再切换到前台
在调用onRestoreInstanceState的情况下,在onSaveInstanceState中保存到Bundle的数据会同时传给onCreate和onRestoreInstanceState,这就是onCeate参数中savedInstanceState的意义,如果不是在onRestoreInstanceState会调用的场景里,savedInstanceState为null
二、两个参数
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)
对应
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState)
public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState)
会对保存的信息做持久化(重启后还能访问)
此组方法调用时机不确定,一直没有模拟出来
相关文章推荐
- UVA 796 Critical Links (桥)
- Mongodb 3节点 Rep set +sharding 配置
- [转] ImageView的android:adjustViewBounds属性
- CodeForces 288C
- Java对象的深复制和浅复制
- Spring上下文ContextLoaderListener作用
- FragmentPagerAdapter实现分页
- iOS 布局重绘机制相关方法的研究
- hdu 5046 Airport 二分+重复覆盖
- pip install 卡住不动的解决方案
- 跳转至系统网络设置界面
- FFPlay 系统结构
- Python 安装requests包问题解决
- 数据结构与算法JavaScript - 队列
- 物联网网关使用中国移动物联卡
- log4j.xml数据库保存日志
- 郁闷的记者_纪中1386_拓扑排序
- Appium滑动和截屏方法封装
- ORA-00257 archiver error. 错误的处理方法
- iOS中最简单实用的自定义动态返回行高的cell,动态计算cell的高度