Leigh McRae wrote:
> At this point
> as far as I can tell that onSaveInstance() must always be called before
> onStop() for this case (being put into the background) as I don't see
> how it can know where I am just popping up a quick options screen and
> then back to my app or leaving the app in the background as I wander off
> into a trail of other apps. 

It doesn't know. By definition, it can't know, since it cannot predict
the future.

> It would be nice to be able to simulate
> this scenario with tools so that my app can be tested.  Would using a
> task killer have the same effect?

No, that will terminate your process.

--------------

Let's flip the problem around. Why does it matter to you if your
activity is destroyed via the BACK button versus via running low on memory?

If the answer is "it doesn't matter", then release your cached stuff in
onDestroy() and be done with it.

If your goal is to release sooner (e.g., onStop()), to be friendlier
about memory consumption while you're not on-screen, and you don't want
to do that too aggressively, set yourself a timer to go off in 30
seconds. Or 30 minutes. Or 30 hours. Whatever you feel is appropriate,
and release your cached stuff then. If the user comes back to your app
before the timer goes off, cancel the timer and just rock on.

onSaveInstanceState() is purely for instance state. In a game, it might
be the score, positions of pieces on the board, and the like -- stuff
that is purely unique to this specific instance of the game. This should
have nothing to do with caching patterns.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training in US: 14-18 June 2010: http://bignerdranch.com

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