Well Tre beat me to it. I was thinking two things. Either A, your main activity registers a listener with another class that uses an AsyncTask in it, and some sort of loop to repeatedly make the rest call. Then, when data is returned, the response handler calls back via the listener and the main activity updates the ui.
The other thought is some static method or class that is constructed with a method in the main activity to call (perhaps via an interface implementation?) and then response handler calls that method with new data, which in turns updates the ui thread. I think the listener is the way to go though. On Mon, Feb 7, 2011 at 7:52 PM, Avtar Khalsa <[email protected]> wrote: > I do need the downloads to continue when the application switches > activities, which is why I am using a service in the first place. It > sounds like registering a listener is the way to go. Thank you so much > for the help! > > On Feb 7, 10:34 pm, TreKing <[email protected]> wrote: > > On Mon, Feb 7, 2011 at 9:24 PM, Avtar Khalsa <[email protected]> > wrote: > > > Thanks for the reply again. It was quite helpful. I am actually > downloading > > > small audio files for an answering machine app. If the activity that > > > launched the service is still running, I would like it to update to > include > > > the newly downloaded files in the UI for the user to listen to. If the > user > > > has moved to a different activity, I just want the service to save the > file > > > to persistent storage. (It will store to persistent storage either way, > but > > > if the activity is running the UI should update) A service seems > appropriate > > > here although I am certainly open to other options? > > > > I guess it depends on the flow and user workflow of your app. If you > start > > your app, it begins downloading, updates the UI as things becomes > available, > > and then shuts down and stops the downloading when the user exist the > > Activity, then I would suggest an AsyncTask. > > > > If the user expects the downloads to continue and somehow play or be > > notified as they become available, then yeah, a Service seems more > > appropriate. > > > > Ultimately, either way will work. > > > > > The issue I am having specifically is notifying the activity that the > > > download is complete. I would really rather avoid having the activity > poll > > > the service to find out if the download is completed > > > > You've seen how most of the UI in Android works? Nearly everything > registers > > a "Listener" object when it wants to know something happens. Create your > own > > listener class like "ServiceListener" or something. Your service takes a > > reference and hold on to it. When a download is complete, it invokes the > > listener's onDownloadComplete() method (or whatever you want to call it). > > > > Meanwhile the Activity is the one that creates an instance of a custom > > listener and passes it to the service. When the service call it's method, > it > > responds appropriately (updating the UI). > > > > You could also send a Broadcast that the Activity would register for, > which > > would set you up for more advance functionality like background > downloading > > and responding to downloading completing without needing your activity to > be > > alive and waiting for the listener to get triggered. Just an idea though, > > the former option is much easier and should suit your current problem > just > > fine. > > > > > --------------------------------------------------------------------------- > ---------------------- > > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago > > transit tracking app for Android-powered devices > > -- > 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 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

