在Activity切换中一般有三种方式保存上一个Activity的状态数据。
一、全局变量
    public static int type = 0;
二、SharedPreference
      保存数据:
    SharedPreferences pf = getSharedPreferences(“saleList”, MODE_WORLD_WRITEABLE);
      SharedPreferences.Editor editor = pf.edit();
      editor.putInt(”stateType”, stateType); 
      editor.commit();
      获取数据:
    SharedPreferences pf = getSharedPreferences(“saleList”, MODE_WORLD_WRITEABLE);
      stateType = pf.getInt(”stateType”, 0);
三、复写onsaveInstanceState()方法
    保存数据:
    @Override
      public void onSaveInstanceState(Bundle outState) {
          // TODO Auto-generated method stub
          outState.putInt("stateType", stateType);
          super.onSaveInstanceState(outState);
      }
      获取数据: 
    @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          stateType = savedInstanceState.getInt("stateType");
      }
事实上,第三种方式的实质也是利用了SharedPreference来保存的数据。

最新文章

  1. Sass:初识Sass与Koala工具的使用
  2. DS18B20函数库建立实验
  3. poj 2051.Argus 解题报告
  4. jQurey基础简介
  5. 在windows上使用symfony创建简易的CMS系统(一)
  6. OpenGL超级宝典第5版&&glProvokingVertex
  7. js-String
  8. vue的组件小操作
  9. docker学习笔记(二)-dockerfile docker仓库
  10. mysql报错Ignoring the redo log due to missing MLOG_CHECKPOINT between
  11. 用js来实现那些数据结构04(栈01-栈的实现)
  12. SSL/TLS Server supports TLSv1.0
  13. What is MaxiSys Pro MS908P Software Advantage
  14. 轻量级web富文本框——wangEditor使用手册(4)——配置下拉菜单 demo
  15. attrs.xml中declare-styleable 详解(用于自定义控件的属性)
  16. 面试总结:QuickSort 解析
  17. leetcode 73 矩阵置零 Python
  18. 腾讯云 利用php + apache + mysql 搭建服务器环境
  19. String类型的学习
  20. VSCode打开文件总是会覆盖上次打开的标签

热门文章

  1. OSX 上安装 Scrapy 的那些坑
  2. impdp使用
  3. node的实践(项目二)
  4. 工作的思考十五:升职前需要做的准备(TeamLeader)
  5. Moqui学习之代码分析mantle priceServices.xml
  6. iOS 使用AFNetworking遇到异常 Request failed: unacceptable content-type: text/html
  7. 另一套Oracle SQL练习题,更新参考答案
  8. Jquery-获取同级标签prev,prevAll,next,nextAll
  9. Java-对象池
  10. Struts tag -s