Articles → Android → Save The State Of The Control If Orientation Is Changed In Android
Save The State Of The Control If Orientation Is Changed In Android
Issue In State After Changing Orientation
Click to Enlarge
Click to Enlarge
Click to Enlarge
How To Save State?
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
outState.putInt("hour", tp.getHour());
outState.putInt("minute", tp.getMinute());
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
tp.setHour(savedInstanceState.getInt("hour"));
tp.setMinute(savedInstanceState.getInt("minute"));
}
Click to Enlarge
Click to Enlarge
Click to Enlarge