Update Running Activity Using Intentservice
Solution 1:
Is that somehow possible?
Use an event bus.
The service posts an event to the bus saying "hey, we got a message!". Your activity, while in the foreground, would be registered on the bus to receive events. If it gets the event, it updates the UI. If, however, the activity is not in the foreground, there are recipes for event bus implementations that would let your service know that the activity did not respond, and so you can raise the Notification
as a fallback mechanism.
There are three major event bus implementations that I know of:
LocalBroadcastManager
: docs and a sample app- greenrobot's EventBus: docs and a sample app
- Square's Otto: docs and a sample app
The sample apps are all the same core app, just using different event bus implementations. I used AlarmManager
to trigger the service rather than a GCM message, but the same concept applies in your case with GCM.
Personally, I like greenrobot's EventBus for the more-flexible threading options, but all three can work in your case.
Post a Comment for "Update Running Activity Using Intentservice"