Sobes.tech
Junior — Middle

In what situations does activity call the onRestoreInstanceState method?

sobes.tech AI

Answer from AI

The onRestoreInstanceState(Bundle savedInstanceState) method is called in an activity after the onStart() method if the system previously saved the activity's state (for example, during a screen rotation or after being destroyed due to low memory). This method is called only if there is a saved state, and it is used to restore the UI and other data that were saved in onSaveInstanceState(Bundle outState).

In other words, onRestoreInstanceState is called when the activity is recreated by the system and there is a saved state to restore.

Example of usage:

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    String text = savedInstanceState.getString("key_text");
    myTextView.setText(text);
}