0

I did a simple program by overriding each of the lifecycle methods and everything works as I'd expect, except for onRestoreInstanceState(Bundle savedInstanceState).

I overrode the method as

@Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);   
    Toast.makeText(getBaseContext(), "onRestoreInstanceState - Activity1 ", Toast.LENGTH_SHORT).show();
    }

But it never gets called.

I overrode onSaveInstanceState(Bundle outState) too and I can see the system calling it, but never the onRestoreInstanceState(Bundle savedInstanceState). When I press back button or so, I can see that the system calls onRestore(), OnStart() and onResume(), and the UI (just two buttons) are displayed correctly.

How is it possible that the UI is restored without calling onRestoreInstanceState(Bundle savedInstanceState)? I only do setContentView(R.layout.main) is onCreate(savedInstanceState). So how does it restore the UI without calling either onCreate() or onRestoreInstanceState()?

Would really appreciate somebody shedding some light on this.

Thank you.

madu
  • 5,232
  • 14
  • 56
  • 96

1 Answers1

0

The documentation here is a bit confusing, but I think this method is only intended as a kind of stand-in for onCreate's handling of stored state, occurring later in the cycle. It's only called if the activity is destroyed and re-created with state; this would most commonly happen during an orientation change. It's not intended to handle state during ordinary transitions between activities.

See also onSaveInstanceState () and onRestoreInstanceState ()

Community
  • 1
  • 1
sosiouxme
  • 1,226
  • 16
  • 26