First I would like to thank you for your hand holding.
On 6/7/2010 10:45 AM, Mark Murphy wrote:
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?
Good point. I guess if I save enough state to be able to reload , it
doesn't matter what happens after onStop(). Currently I have a bug with
my game Wrath on the Android Market where a static variable is NULL and
I can't see how this could happen. Using singleTask launch mode didn't
fix it so I was thinking it was a lack of understand the activity life
cycle but perhaps it's something else.
Thanks for the help Mark.
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.
--
Leigh McRae
www.lonedwarfgames.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