android onSaveInstanceState()及其配对方法。
转自:http://blog.chinaunix.net/uid-22985736-id-2977672.html
onSaveInstanceState() 和 onRestoreInstanceState()不属于Activity的生命周期,只有意外销毁一个Activity时才被调用,如内存不足,按下了HOME键(注:按下BACK键则是主动销毁一个Activity,这两个方法不会被调用)。当需要改变屏幕方向时,也可以用这两个方法来暂存一些数据。
下面百度地图应用中的例子,就用到了这两种方法,用来保存和恢复地图的视图。
@Override
protected void onSaveInstanceState(Bundle outState) {
cPoint = mapView.getMapCenter(); //得到当前MapView的中心点。
outState.putInt("lat", cPoint.getLatitudeE6()); //暂存在outState中
outState.putInt("lon", cPoint.getLongitudeE6());
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
int lat = savedInstanceState.getInt("lat"); //从保存的数据中恢复
int lon = savedInstanceState.getInt("lon");
cPoint = new GeoPoint(lat, lon);
super.onRestoreInstanceState(savedInstanceState);
}
android onSaveInstanceState()及其配对方法。的更多相关文章
- Android Activity的onSaveInstanceState() 和 onRestoreInstanceState()方法:
Android Activity的onSaveInstanceState() 和 onRestoreInstanceState()方法: 1. 基本作用: Activity的 onSaveInstan ...
- Android onSaveInstanceState和onRestoreInstanceState()
首先来介绍onSaveInstanceState() 和 onRestoreInstanceState() .关于这两个方法,一些朋友可能在Android开发过程中很少用到,但在有时候掌握其用法会帮我 ...
- Android蓝牙自动配对Demo,亲测好使!!!
蓝牙自动配对,即搜索到其它蓝牙设备之后直接进行配对,不需要弹出配对确认框或者密钥输入框. 转载请注明出处http://blog.csdn.net/qq_25827845/article/details ...
- Android蓝牙自动配对Demo,亲测好使!!!(转)
蓝牙自动配对,即搜索到其它蓝牙设备之后直接进行配对,不需要弹出配对确认框或者密钥输入框. 转载请注明出处http://blog.csdn.net/qq_25827845/article/details ...
- 【Android】一种提高Android应用进程存活率新方法
[Android]一种提高Android应用进程存活率新方法 SkySeraph Jun. 19st 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph ...
- Android经典完美退出方法
Android经典完美退出方法,使用单例模式创建一个Activity管理对象,该对象中有一个Activity容器(具体实现自己处理,使用LinkedList等)专门负责存储新开启的每一个Activit ...
- Android获取系统时间方法的总结
Android获取系统时间方法的方法有很多种,常用的有Calendar.Date.currentTimeMills等方法. (1)Calendar Calendar获取系统时间首先要用Calendar ...
- 删除Android自带软件方法及adb remount 失败解决方案
删除Android自带软件方法 1.在电脑上打开cmd,然后输入命令 adb remount adb shell su 2.接着就是Linux命令行模式了,输入 cd system/app 3然后输入 ...
- PhoneGap 在 Android 上的插件开发方法介绍
移动应用开发已经成为软件开发的一个重要方向,但是移动开发面临的一个重要问题就是跨平台的问题.PhoneGap 作为一个多平台的软件开发框架,提供了一次编写多个平台的运行.目前已经支持多达 6 个移动平 ...
随机推荐
- learning armbian steps(2) ----- armbian 镜像编译
参考:https://docs.armbian.com/Developer-Guide_Build-Preparation/ 通过如下指令进行编译: apt-get -y -qq install gi ...
- java修饰符的作用范围
访问修饰符: private 缺省 protected public 作用范围: private 被private修饰的属性和方法,不能被其他类访问,子类不能继承也不能访问.只能在所在类内部访问.缺省 ...
- hdu 1159 Common Subsequence (最长公共子序列 +代码)
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- windows安装redis和php拓展
第一步:下载redis 我是win7的环境,直接到https://github.com/MSOpenTech/redis/releases下载windows版本的redis: 第二步:配置path i ...
- xml与json
JSON(JavaScript Object Notation)是一种轻量级的数据交换格式. JSON现在基本上作为前后端数据交互的重要载体,在JSON之前,前后端主要的传输方式主要是通过XML或者文 ...
- ACCESS删除datagridview和数据库中的一条数据,同时更新显示的方法源码
//删除,行删除 private void 删除_Click(object sender, EventArgs e) { int dgrcount = dataGridView1.SelectedRo ...
- 一年内自学MIT的33门课? 疯狂学习有方法
[导读]能快速掌握复杂信息,对成就卓越事业至关重要.ScottYoung的学习过程不只适用于学生,同样有助于学习复杂技能的专业知识. 能快速掌握复杂信息,对成就卓越事业至关重要.ScottYoung的 ...
- $data[$i++]+=2;不等于$data[$i++]=$data[$i++]+2;
$data=array(1,2,3,4); $i=1; $data[$i++]+=2; var_dump($data); echo $i; //输出:array(1,4,3,4) 和 2 $data= ...
- linux下普通用户无法使用sudo命令问题
今天在新装的linux虚拟机中使用sudo命令时,报错如下 We trust you have received the usual lecture from the local System Adm ...
- 实习第一天:try和catch的使用
package wo;public class wowo{ public static void main(String[] args){ try{ // int i = 1/0; 是没有语法错误的, ...