Thanks for the replies. Kevin, what I'm trying to accomplish is [seemingly] very common in the mobile world:
1) User starts app 2) App retrieves info from remote server based on the User's interaction with the app 3) When app is not in focus (or closed) a background service continues to retrieve updates from remote server For point number 2), I understand that I could simply use a background thread (eg. AsyncTask), since the data is to be returned to the current activity. But for point number 3), a simple background thread is not appropriate. My question is this: Since I will need to write a service to perform [much of] the same functionality in point 3) as my background service will be performing in point 2), wouldn't it just make more sense to skip the background thread and perform all of my polling through the service - and simply call that service from within whatever activity may need it at the time? But that raises another question: calling a service from an activity seems to lock the UI - so when polling remote servers, shouldn't the service either be run in a new thread, or rather, shouldn't the service spawn its own thread? On Jan 19, 4:22 pm, Kevin Duffey <[email protected]> wrote: > One thing you haven't indicated is if you need this remote access when the > app starts, or if you actually need to periodically "wake up" and poll the > remote service? If you only need to have a user start your app.. and at that > point it requests to the remote service once.. or while the app is running, > then using AsyncTask is the way to go. If you need your app to periodically > poll the remote service, than a service may be the way to go. A service > would not require a separate thread that I know of because it is not tied to > a UI. It's a background task, with no UI. > > On Tue, Jan 19, 2010 at 1:14 PM, jotobjects <[email protected]> wrote: > > I don't think it will accomplish anything to start a service in a > > thread. That doesn't make the service run in the thread where it is > > started. So you are down to one of the options you are considering. > > Ti si also possible to start a service in a separate process but it > > still should not block on its main thread. > > > Possibly android.os.AsyncTask will be useful for you. > > > On Jan 18, 5:17 pm, Flapjack <[email protected]> wrote: > > > Please forgive my ignorance, I am new to Java and Android. > > > > I would like to retrieve remote data and display it within my > > > activity. To prevent tying up to UI, I understand that I can do this > > > in another thread. (I thought I could just-as-well fetch this remote > > > data from within a service, but that appears to tie up the UI thread > > > also). So now I'm beginning to think I need to either run the logic > > > from a new thread within a service, or run a service within a new > > > thread. But which? I have found many examples online of running new > > > threads or services, but I have yet to find an example of both at the > > > same time. > > > > Thanks! > > > -- > > 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]<android-developers%[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 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

