Implement onSaveInstanceState
like so:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save the user's current game state
savedInstanceState.putInt("STATE_DELAY", delay);
savedInstanceState.putInt("STATE_PERIOD", period);
// Always call the superclass so it can save the view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}
and then inside your onCreate
try to restore them (if they have been set) like so:
// Check whether we're recreating a previously destroyed instance
if (savedInstanceState != null) {
// Restore value of members from saved state
delay = savedInstanceState.getInt("STATE_DELAY");
period = savedInstanceState.getInt("STATE_PERIOD");
}
And finally as I wrote in the comments of the question have a look at the Recreating an Activity training page.