1.给控件增加id,就能让控件状态保存(屏幕切换时)
因为activity里面有onSaveInstanceState()方法
2.对于不能保存的,需要重写onSaveInstanceState方法(比如变量的值)
例子::private String str="需要保存的值";
protected void onSaveInstanceState(Bundle outState) {
outState.putString("key",str);
super.onSaveInstanceState(outState);
} //保存信息
protected void onRestoreInstanceState(Bundle savedInstanceState) { //或者用activity中的onCreate()方法恢复
super.onRestoreInstanceState(savedInstanceState);
if(savedInstanceState==null)
return;
String str=savedInstanceState.getString("key");
} //恢复信息 |
|