So, MyActivity will have a progress bar. MyActivity's BroadcastReceiver will catch the intent "START_TASK". After that, as time passes, I want to update MyActivity's progress bar. I was originally trying to handle this from a service, but I don't know how to access MyActivity's progress bar from a service (or how to create a progress bar in the service and place it on MyActivity's screen).
-
I'm open to another way of making this work as well. I'm not particular about the method as long as I can get it to work. – Brianide Dec 13 '11 at 18:14
-
There is plenty examples of how to use a progressbar out there :) – Warpzit Dec 14 '11 at 13:49
1 Answers
You don't access an Activity's progress bar from a service: you have the service send messages to your activity, at a rate appropriate to whatever it is you're trying to do, and make your activity respond to those messages by updating its own progress bar.
It would help if you could give a little more detail about the nature of the background task you want the progress bar to track: if the background task is the important thing, and the activity is merely showing you how it's progressing, then a service is the right thing to use. If it's short-lived and doesn't make sense outside then activity then you'd probably be using an AsyncTask and updating the progress bar in its onProgressUpdate (although be careful you don't leak the AsyncTask when the screen orientation changes).
Maybe look here: How to have Android Service communicate with Activity

- 1
- 1

- 3,343
- 1
- 30
- 41
-
Thanks. I'll look into this more tonight. I tried to get this working yesterday by having my service broadcast every second to my Activity, but something isn't happening correctly. I'll post up some code later. – Brianide Dec 14 '11 at 16:58