Agreed, Bob. I will pursue your above route :)

Dimitris- Thanks for the input. I have read the Activity lifecycle
docs and believe I have a pretty solid understanding of the Activity
lifecycle, this issue is however more related to the Service
lifecycle.


On Apr 17, 2:53 pm, Bob Kerns <r...@acm.org> wrote:
> If this were a matter of saving the data, then onPause() is indeed the
> place to do the work. However, it's not appropriate here.
>
> This is not something you want to pause. You increase the chances of
> connection failure, and you consume resources on the server. Don't do
> that.
>
> You also don't want to stop it there, and restart it on resume.  That
> just causes extra work, and minimizes your chance of success.
>
> onDestroy() is the right place to actually destroy the background
> activity here, if you want it to continue while the activity continues
> to be "active". Yes, in some circumstances onDestroy() won't be
> called, and the process will just be deleted. That will also nuke the
> service, though, so that doesn't present a problem.
>
> On Apr 17, 11:02 am, Dimitris <dnkou...@gmail.com> wrote:
>
>
>
>
>
> > I would take into consideration that onDestroy() might not get called
> > always. Usually onPause() is the best place to store/cache data before
> > you are done because it is guaranteed to get called. Keep in mind not
> > to do "expensive" or time consuming operations onPause() because the
> > other activity that is trying to show won't show until your onPause()
> > is done.
>
> > I recommend reading the Android activity life cycle docs on the
> > android dev docs.
>
> > Enjoy :)
>
> > On Apr 17, 3:45 am, patbenatar <patbena...@gmail.com> wrote:
>
> > > Awesome. Thanks Bob! This has been very informative. I will pursue
> > > this route :)
>
> > > On Apr 16, 11:47 pm, Bob Kerns <r...@acm.org> wrote:
>
> > > > You are 100% on the right track; this calls for a service.
>
> > > > As for what happens when your activity is no longer running -- well,
> > > > let's consider that.
>
> > > > First, if your activity is simply no longer the current activity --
> > > > the user may have pressed Home, for example -- he may switch back to
> > > > it. You'd like to have actually made some progress in the meantime --
> > > > especially if he left because he was tired of waiting for the
> > > > transfer. You probably want to let the transfer continue until
> > > > onDestroy() is called on your Activity, at which point you can stop
> > > > the service.
>
> > > > If your activity is truly gone -- well, would that information be
> > > > useful if he started up your program again later? If so, you might
> > > > want to consider allowing the transfer to finish, and caching the
> > > > result. In this model, the activity's onDestroy() method leaves the
> > > > service alone, and the service calls stopSelf() when it's done. Next
> > > > time it's started for this purpose, it can check for the cached data
> > > > and immediately supply that.
>
> > > > If caching is inappropriate, and you want it to only run when the
> > > > Activity is still alive, then use bindServce() instead of
> > > > startService(), and  unbind the service in the Activity's onDestroy().
> > > > The Service can track how many bindings are active, and exit early out
> > > > of its loop reading the data. You couldn't do any better than this at
> > > > stopping the activity even if you were doing it in the Activity
> > > > anyway.
>
> > > > On Apr 16, 9:57 pm, patbenatar <patbena...@gmail.com> wrote:
>
> > > > > Hey all-
>
> > > > > I've run into an interesting little issue.. My loader Activity fetches
> > > > > data from a web API, starting an http request and waiting for the
> > > > > result.. Now what if the user flips their phone mid-http request? The
> > > > > Activity is destroyed and restarted, thus the http request restarts as
> > > > > well. The fact that my Activity is being destroyed on orientation
> > > > > change is all good by me, I understand the way Android works, I'm just
> > > > > looking for a solution to avoid restarting the http request on every
> > > > > orientation change..
>
> > > > > I'm thinking the solution would be Services... I could run a Service
> > > > > in the background to do the http request and when it finishes, call
> > > > > back to my Activity and let it handle the data and finish up. The one
> > > > > thing I'm a bit weirded out about is what if the user closes my app
> > > > > before the Service's http request finishes? What will it do with the
> > > > > data if the Activity that needs it is no longer running?
>
> > > > > Thoughts, feedback, ideas, etc would be great!
>
> > > > > Thanks,
> > > > > Nick
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > > > Groups "Android Developers" group.
> > > > > To post to this group, send email to 
> > > > > android-developers@googlegroups.com
> > > > > To unsubscribe from this group, send email to
> > > > > android-developers+unsubscr...@googlegroups.com
> > > > > For more options, visit this group 
> > > > > athttp://groups.google.com/group/android-developers?hl=en
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Android Developers" group.
> > > > To post to this group, send email to android-developers@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > android-developers+unsubscr...@googlegroups.com
> > > > For more options, visit this group 
> > > > athttp://groups.google.com/group/android-developers?hl=en
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/android-developers?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com
> > For more options, visit this group 
> > athttp://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

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

Reply via email to