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 ?
Asked
Active
Viewed 435 times
0
-
refer http://stackoverflow.com/questions/14695537/android-update-activity-ui-from-service – sasikumar Sep 19 '15 at 10:19
-
use a "local bound service" pattern, what you need from your `Activity` is simply call `bindService` – pskink Sep 19 '15 at 11:00
1 Answers
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