Activity重新创建之recreate
来源:互联网 发布:淘宝哪里申请换货 编辑:程序博客网 时间:2024/04/29 04:38
Android在3.0之后,Activity引入了新的一个方法:recreate(),从字面意思就知道是重新创建Activity的,3.0+版本才可以使用。
/** * 调用recreate方法重新创建Activity会比正常启动Activity多调用了onSaveInstanceState * ()和onRestoreInstanceState()两个方法,onSaveInstanceState()会在onCreate方法之前调用。 * 所以可以在onCreate()方法中获取onSaveInstanceState()保存的Theme数据 * * @description: * @author ldm * @date 2016-4-19 上午9:34:49 */public class MainActivity extends Activity implements OnClickListener { private Button recreate; private int mCurrentTheme; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 从onSaveInstanceState(Bundle outState)方法中保存的数据取出Theme if (savedInstanceState != null) { mCurrentTheme = savedInstanceState.getInt("mCurrentTheme"); // 切换Activity的Theme switch (mCurrentTheme) { case android.R.style.Theme_Holo_Light: mCurrentTheme = android.R.style.Theme_Holo_Dialog; break; case android.R.style.Theme_Holo_Dialog: mCurrentTheme = android.R.style.Theme_Holo; break; default: mCurrentTheme = android.R.style.Theme_Holo_Light; break; } setTheme(mCurrentTheme); } setContentView(R.layout.activity_main); this.recreate = (Button) findViewById(R.id.recreate); this.recreate.setOnClickListener(this); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("mCurrentTheme", mCurrentTheme);// 把当前Theme保存 } @Override public void onClick(View v) { recreate();// 直接调用Activity的recreate()方法重启Activity }}
0 0
- Activity重新创建之recreate
- ApiDemos之activity recreate方法
- Android Activity 之 重新创建
- Activity生命周期 之 重新创建一个Activity
- 谈谈Fragment的构造函数、重新创建(recreate)及相关
- Activity生命周期之重新创建Activity(recreating activity)
- Activity的重新创建
- 重新创建activity
- 重新创建Activity
- 重新创建一个Activity
- 重新创建Activity
- Activity重新创建
- 重新创建Activity
- 重新创建Activity
- 重新创建Activity
- 防止Activity被重新创建
- 【Android】非 recreate() 形式的夜间模式实现(自由切换,不改变任何状态,不重新初始化整个activity)
- [Andriod官方训练教程]管理Activity的生命活动之重新创建一个Activity
- Web Service 那点事儿(3)—— SOAP 及其安全控制
- Java网络编程-初识Socket
- Python实现MapReduce
- 支付宝钱包系统架构内部剖析(架构图)
- iOS开发之xib 加载xib视图需要用到的方法
- Activity重新创建之recreate
- BZOJ 3676 UOJ 103 APIO 2014 后缀自动机 Manacher
- FOJ 2214 Knapsack problem 第六届福建省大学生程序设计竞赛 C 01背包DP变种
- SQLite数据库笔记
- dstat默认输出说明
- Eclipse使用入门教程
- 什么是库?(linux平台下的理解)
- 正则表达式在iOS中的运用
- 修改JAVA_HOME无效,java版本保持不变的问题解决