On Tue, Mar 5, 2013 at 6:09 PM, TreKing <[email protected]> wrote:

>
> On Tue, Mar 5, 2013 at 10:14 AM, Latimerius <[email protected]> wrote:
>
>> On Tue, Mar 5, 2013 at 4:41 PM, Piren <[email protected]> wrote:
>>
>>> Not sure what the issues you mention, never had those...
>>> onPause/onResume are pretty much the only lifecycle events that are
>>> constant in behavior :)
>>>
>>>
>> I described it in my original post - in short, if the main activity is
>> being paused because the user is leaving the app, a lot of things have to
>> be closed, saved, cleaned up etc.  If it's being paused just to show
>> preferences, those things should not happen.
>>
>
> I may have misses something, but from what you've described, I think you
> might be overcomplicating things and should probably just be using the
> lifecycle events. In this case, onDestroy for all this cleanup. onDestroy
> will be called when the user leaves the app by pressing back. It will NOT
> be called when they press Home, but that's expected because they're not *
> leaving* the app, they're merely sending it to the background, so your
> app should not completely shut down and should be ready to quickly resume
> should the user switch back to it.
>
> Eventually, if the user never returns to your app, it will be killed off
> by the system and whether or not onDestroy gets called all your stuff will
> be "closed" anyway.
>

Unfortunately, onDestroy() is really too late for the requirements I have.
 I shouldn't keep threads running until onDestroy() as that could eat quite
a lot of battery power over time.  Also, audio has to be stopped as soon as
user leaves the app.  The same goes for analytics session, it should to be
closed right when the user leaves otherwise it would be hard to get
accurate data about session length.  And for saving data, onDestroy() is
explicitly documented to be a bad choice.

For all of these things, there's the ideal place to perform them -
onPause(), but only if it means the user is leaving the app.  You don't
want to do any of those just because you need to display what amounts to a
bloody dialog. ;-)


> However, if this is for a game, then I believe those are usually
> implemented with a single Activity to allow you to better control resources
> like graphics and music. Then you don't have the music playing issue you
> describe since you just handle onPause / onStop to pause the music.
>
>
Yes, it is a game (a toy, more precisely), and I'm just in the process of
figuring out how to make sure I'll only ever have a single activity (which
means at the moment how to get rid of my PreferenceActivity).

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to