On Jun 8, 4:38 am, Leigh McRae <[email protected]> wrote:

> The common case is where an activity is put into the background and
> isn't killed for memory.  Forcing an Activity to save it's state when
> it's not required is a waste of resources on a resource scarce platform.

I think the important point here is "resource scarce platform."
Because there's no way to predict how many system resources the new
foreground activity is going to use, there's also no way to predict
how likely it is that your activity (now in the background) is going
to get destroyed. Therefore, it's *required* that your activity save
its state whenever it goes into the background. The OS can not know
when - or even if - your activity will receive focus again.

By the time it becomes necessary to kill your process "for memory" -
if indeed that does become necessary - there may not be enough system
resources left to let you save your instance state. Again, this is all
because it's a "resource scarce platform." The OS only starts killing
processes when those resources are in high demand.

If your activity has a LOT of state to save, then you probably need to
think about re-architecting it to save some state as it goes along,
rather than waiting for onSaveInstanceState() to do it all. There's
another thread going on elsewhere on this group about the default
Android browser having this exact problem in extreme cases, and it's
emerged (from one of the Android platform engineers) that the OS only
gives a process 1/5 second to save state before pushing it into the
background. If your instance state takes longer than this to save, you
definitely need to look at doing it another way.

But in any case, the point is that whenever your activity loses the
foreground, there's no guarantee possible that the same instance will
ever come back to the foreground. So any state which you haven't saved
is liable to be lost.

String

-- 
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