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


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, January 09, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250