android onSaveInstanceState的使用方法
2016-11-28 16:37
423 查看
[java] view
plain copy
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.slee
18838
p(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;
}
}
[java] view
plain copy
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;
}
}
plain copy
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.slee
18838
p(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;
}
}
[java] view
plain copy
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;
}
}
相关文章推荐
- android onSaveInstanceState的使用方法
- android onSaveInstanceState的使用方法
- Android BaseSavedState 以及 Activity onSaveInstanceState 和 onRestoreInstanceState 方法使用注意事项
- Android 中 onSaveInstanceState()使用方法详解
- android onSaveInstanceState的使用方法
- android onSaveInstanceState方法 横坚屏切换的状态保存
- Android Activity的onSaveInstanceState() 和 onRestoreInstanceState()方法
- onSaveInstanceState()方法使用注意点
- android onSaveInstanceState方法 横坚屏切换
- Android中用onSaveInstanceState保存Fragment状态的方法
- Android 状态保存 生命周期 onSaveInstanceState onRestoreInstanceState 方法
- Android onSaveInstanceState的使用
- Android编程——自定义View类onSaveInstanceState与onRestoreInstanceState使用方法
- (转载)-- android onSaveInstanceState方法
- Android Activity的onSaveInstanceState() 和 onRestoreInstanceState()方法
- android onSaveInstanceState方法
- android onSaveInstanceState 方法
- Android编程——自定义View类onSaveInstanceState与onRestoreInstanceState使用方法
- android:Can not perform this action after onSaveInstanceState解决方法
- View 和 AbsListView中的onSaveInstanceState()方法以及onRestoreInstanceState()方法的使用