> Now I found out that there is a problem with that:
> * When the other activity ("ActivityB" in my example) is started,
> ActivityA's onSaveInstanceState is called (why?).
The reason for this, because while ActivityB is shown, ActivityA there
is a _posibility_ that ActivityA can be killed for some reason (for
example low resources, orientationchange etc.). Because of that, it's
necessary that ActivityA saves it's state otherwise it would lose its
data on screenflip while ActivityB is shown during the oriantation
change

> * While changing the screen orientation when ActivityB is shown in the
> foreground and ActivityA in the background, onSaveInstanceState and
> onRestoreInstanceState are not called for ActivityA.

Yes, because onSaveInstancedState was already called when the
ActivityB came in the foreground. However, it should be called after
you close ActivityB (but only after a screen oriantation change). If
the screen oriantation change didn't occur (or ActivityA wasn't killed
due to low resources), there is no need to recreate the ActivityA as
nothing changed.

This is from what i know a part of the optimization.
onRestoreInstaceState will only be called if it's necessary otherwise
it wont be called to save from unnecessary recreating of the UI/extra
processing. Less processing = less power consumption = longer battery
life before you have to recharge.


> In my example, this means that the content of the textbox of ActivityA
> is properly restored when ActivityB is shown in the foreground only on
> the first screen orientation change, but not when changing the
> orientation for a second time.

Does it also happen, if you start ActivityB, flip the screen, flip it
back and close ActivityB?
Usually then the onRestoreInstaceState of ActivityA should be called


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to