0

I want to create a service that runs in the background, service upload files to a server . meanwhile you can close the app . the service continues to work , at the end and, if the app is open must update the UI of the app . as you update the UI of the app if it's open ? I have to make a check of the type : if app open ui update ?and how to do this ?

Pinco Panco
  • 253
  • 1
  • 3
  • 7

1 Answers1

0

Use an event bus, such as greenrobot's EventBus or LocalBroadcastManager. The service can post a message to the bus, announcing any state changes. The activity — if it exists — can subscribe for messages from the bus and update the UI upon receipt of this state-change message.

I have sample apps demonstrating this for greenrobot's EventBus and for LocalBroadcastManager. I also have one for Square's Otto, though it is a bit more complicated due to threading issues.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491