android onSaveInstanceState的使用方法
来源:互联网 发布:淘宝过期化妆品 编辑:程序博客网 时间:2024/06/06 09:16
package com.saveInstanceDemo.src;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.util.Log;public class saveInstanceDemo extends Activity { private static final String TAG = "MyNewLog"; private int mCount = 0; private boolean mThreadDisble; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // If an instance of this activity had previously stopped, we can // get the original text it started with. if(null != savedInstanceState) { int IntTest = savedInstanceState.getInt("IntTest"); String StrTest = savedInstanceState.getString("StrTest"); Log.e(TAG, "onCreate get the savedInstanceState+IntTest="+IntTest+"+StrTest="+StrTest); } setContentView(R.layout.main); new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub while(true) { if(!mThreadDisble) { Log.v(TAG, Boolean.toString(mThreadDisble)); try{ Thread.sleep(1000); } catch(Exception e) { e.printStackTrace(); } mCount++; Log.v(TAG, "mCount : " + mCount); } } } }).start(); Log.e(TAG, "onCreate"); } @Override //为了防止万一程序被销毁的风险,这个方法可以保证重要数据的正确性 //不写这个方法并不意味着一定出错,但是一旦遇到了一些非常奇怪的数据问题的时候 //可以看看是不是由于某些重要的数据没有保存,在程序被销毁时被重置 public void onSaveInstanceState(Bundle savedInstanceState) { // Save away the original text, so we still have it if the activity // needs to be killed while paused. savedInstanceState.putInt("IntTest", mCount); savedInstanceState.putString("StrTest", "savedInstanceState test"); super.onSaveInstanceState(savedInstanceState); Log.e(TAG, "onSaveInstanceState"); } @Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); int mCount = savedInstanceState.getInt("IntTest"); String StrTest = savedInstanceState.getString("StrTest"); Log.e(TAG, "onRestoreInstanceState+IntTest="+mCount+"+StrTest="+StrTest); } public void onDestroy() { super.onDestroy(); this.mThreadDisble = true; } public void onPause() { Log.v(TAG, "onPause"); super.onPause(); mThreadDisble = true; } public void onResume() { Log.v(TAG, "onResume"); super.onResume(); mThreadDisble = false; }}
0 0
- android onSaveInstanceState的使用方法
- android onSaveInstanceState的使用方法
- android onSaveInstanceState的使用方法
- android onSaveInstanceState的使用方法
- onSaveInstanceState和onRestoreInstanceState的使用方法
- onSaveInstanceState 和onRestoreInstanceState的使用方法
- Android onSaveInstanceState的使用
- android的onSaveInstanceState的调用
- Android - 解决onSaveInstanceState的Bug
- [Android] onSaveInstanceState()
- Android onSaveInstanceState和onRestoreInstanceState触发的时机
- Android onSaveInstanceState和onRestoreInstanceState触发的时机
- Android onSaveInstanceState和onRestoreInstanceState触发的时机
- Android Activity的onSaveInstanceState() 和 onRestoreInstanceState
- Android的onSaveInstanceState和onRestoreInstanceState用法
- Android onSaveInstanceState和onpause的区别
- Android onPause和onSaveInstanceState的区别
- Android Activity的onSaveInstanceState() 和 onRestoreInstanceState()方法
- AndroidStudio导入github项目
- oracle序列详解
- Excel 1
- 2016-06-17 nui构件隐藏时相关属性的设置 bug命名【彩虹】
- 27.javaScript面向对象基础-02
- android onSaveInstanceState的使用方法
- 专题四1001
- ios aop 和 swizzmethod
- hdu 5584 LCM Walk 2015ACM/ICPC亚洲区上海站-重现赛
- 将JSON数据转换成对象
- Java WebService 简单实例
- java利用CountDownLatch来制定线程执行顺序
- leetcode 194. Transpose File
- Ajax学习(二)