How to use onSaveInstanceState

I redefine the function below onSaveInstanceState

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
   super.onSaveInstanceState(savedInstanceState);
}

I have a question. What a problem if I omit **super.onSaveInstanceState(savedInstanceState)** , so the function will look like

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
   //super.onSaveInstanceState(savedInstanceState);
}

I hope you can explain to me how detailed, better

+4
source share
4 answers

If you omit this (causing the implementation of the dinner), then you will need to find a way to save your data (which will include a mechanism that will allow you to check whether the state is saved).

A method super.onSaveInstanceState(Bundle);writes a packet and everything that it contains in a related object that activity (fragment) can receive a method in it onCreate(Bundle). There is information here .

, . , . @CapDroid , , .

Lifecycle .

+2

onSaveInstanceState (Bundle savedInstanceState) - , pause. , - , , .

, onSaveInstanceState

@Override
public void onSaveInstanceState(Bundle outState) {

   outState.putString("message", "This is my message to be reloaded");
   super.onSaveInstanceState(outState);
}

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  if( savedInstanceState != null ) {
     Toast.makeText(this, savedInstanceState .getString("message"), Toast.LENGTH_LONG).show();
  }
}

: ,

super.onSaveInstanceState(outState);, . , , . OnCreate, .

+2

onSaveInstanceState, Activity ( Fragment) .

, - .

, EditText, , , , EditText (, ) , ​​ ( ).

, super.onSaveInstanceState .

0

super.onSaveInstanceState(), View s.

If you do not call super.onSaveInstanceState(), then if your application is killed when it is in the background, your Viewwill be reinitialized (as if it were created) when the user returns to your application.

0
source

All Articles