public class MainActivity
extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState !=
null) {
//判断是否有以前的保存状态信息
savedInstanceState.get(
"Key")
;
}
super.onCreate(savedInstanceState)
;
setContentView(R.layout.activity_main)
;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
//可能被回收内存前保存状态和信息,
Bundle data =
new Bundle()
;
data.putString(
"key", "last words before be kill")
;
outState.putAll(data)
;
super.onSaveInstanceState(outState)
;
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
if (savedInstanceState !=
null) {
//判断是否有以前的保存状态信息
savedInstanceState.get(
"Key")
;
}
super.onRestoreInstanceState(savedInstanceState)
;
}
}
转载请注明原文地址: https://ju.6miu.com/read-676258.html