3

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).

Chris
  • 44,602
  • 16
  • 137
  • 156
Brianide
  • 461
  • 1
  • 6
  • 17

1 Answers1

1

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

Community
  • 1
  • 1
android.weasel
  • 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