This kind of questions appear periodically. Sorry if this has been covered before, but I\'m a newbie and couldn\'t find the appropriate answer. It deals with the correct impleme
Try this code to store the values for the activity
Long value;
protected void onSaveInstanceState(Bundle onOrientChange) {
super.onSaveInstanceState(onOrientChange);
onOrientChange.putLong("myValue", value);
}
And restore the values in onCreate():
public void onCreate(Bundle onOrientChange) {
if (onOrientChange!= null){
value = onOrientChange.getLong("myValue");
}
}
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()