博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Saving Activity state in Android
阅读量:5125 次
发布时间:2019-06-13

本文共 1450 字,大约阅读时间需要 4 分钟。

 
You need to override onSaveInstanceState(Bundle savedInstanceState) and write the application state values you want to change to the Bundle parameter like this:
 
@Overridepublic void onSaveInstanceState(Bundle savedInstanceState) {  super.onSaveInstanceState(savedInstanceState);  // Save UI state changes to the savedInstanceState.  // This bundle will be passed to onCreate if the process is  // killed and restarted.  savedInstanceState.putBoolean("MyBoolean", true);  savedInstanceState.putDouble("myDouble", 1.9);  savedInstanceState.putInt("MyInt", 1);  savedInstanceState.putString("MyString", "Welcome back to Android");  // etc.} The Bundle is essentially a way of storing a NVP ("Name-Value Pair") map, and it will get passed in to onCreate and also onRestoreInstanceState where you'd extract the values like this:@Overridepublic void onRestoreInstanceState(Bundle savedInstanceState) {  super.onRestoreInstanceState(savedInstanceState);  // Restore UI state from the savedInstanceState.  // This bundle has also been passed to onCreate.  boolean myBoolean = savedInstanceState.getBoolean("MyBoolean");  double myDouble = savedInstanceState.getDouble("myDouble");  int myInt = savedInstanceState.getInt("MyInt");  String myString = savedInstanceState.getString("MyString");}You did usually use this technique to store instance values for your application (selections, unsaved text, etc.).

 

原文:

转载于:https://www.cnblogs.com/veins/p/3730979.html

你可能感兴趣的文章
Python简介
查看>>
VS2010安装异常中断后无法安装的解决方法(安装时发生严重错误)
查看>>
React Native 开发环境搭建
查看>>
冒泡排序
查看>>
python全栈学习总结三:函数学习
查看>>
【4.0】jdbcTemplate
查看>>
redis 分布式锁实现
查看>>
屏幕尺寸
查看>>
android中实现简单的播放
查看>>
http和https协议
查看>>
HDOJ 4253 Two Famous Companies 二分+MST
查看>>
CSE2DBF 2019
查看>>
BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会 树形DP + 带权重心
查看>>
java保留两位小数
查看>>
滚动侦测scrollspy
查看>>
Navicat 连接MariaDB 失败: Host '*' is not allowed to connect to this MariaDB server
查看>>
条件、循环、函数定义 练习
查看>>
Sql语句之递归查询
查看>>
模式(一)javascript设计模式
查看>>
关于构造函数和this调用的思考
查看>>