80,330
社区成员
发帖
与我相关
我的任务
分享
package com.androidbook;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class HelloActivity extends Activity {
private static final String TAG = "MyNewLog";
/** Called when the activity is first created. */
@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);
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", 0);
savedInstanceState.putString("StrTest", "savedInstanceState test");
super.onSaveInstanceState(savedInstanceState);
Log.e(TAG, "onSaveInstanceState");
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
int IntTest = savedInstanceState.getInt("IntTest");
String StrTest = savedInstanceState.getString("StrTest");
Log.e(TAG, "onRestoreInstanceState+IntTest="+IntTest+"+StrTest="+StrTest);
}
}