views:

508

answers:

1

Hi,

this is the current state/situation: I have an Activity which binds a Service which creates AsyncTasks which downloads various web resources. That works well, but of course the ProgressBar shows nothing.

Previously i had an Activity which created an AsyncTask which downloaded some stuff. The AsyncTask got the View which holds the ProgressBar. So i could update the progress using onProgressUpdate and publishProgress. Obviously this doesn't work any longer because I have no reference to the ProgressBar.

So, do you have any idea on how to update the progress?

Thanks in advance.

+3  A: 

Have the Service notify the then-running Activity about the progress from onProgressUpdate(). That could be via a broadcast Intent, or via a callback object registered by the Activity (and unregistered when the Activity is destroyed, such as on a screen rotation).

CommonsWare
Thanks. I have now a class ProgressReceiver which extends BroadcastReceiver. The Intents from onProgressUpdate() get there and i can read the progress out of them. But how can I update the ProgressBar?Sorry, i don't get it :(
dAnjou
Make that ProgressReceiver be an inner class of your Activity, registered via registerReceiver() and unregistered via unregisterReceiver(). Then, ProgressReceiver can just call setProgress() or incrementProgressBy() on your ProgressBar.
CommonsWare
Ah yes, that works. Thanks a lot.
dAnjou