Usually you restore your state in onCreate()
. It is possible to restore it in onRestoreInstanceState()
as well, but not very common. (onRestoreInstanceState()
is called after onStart()
, whereas onCreate()
is called before onStart()
.
Use the put methods to store values in onSaveInstanceState()
:
protected void onSaveInstanceState(Bundle icicle) {
super.onSaveInstanceState(icicle);
icicle.putLong("param", value);
}
And restore the values in onCreate()
:
public void onCreate(Bundle icicle) {
if (icicle != null){
value = icicle.getLong("param");
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…