Skip to content Skip to sidebar Skip to footer

Update Running Activity Using Intentservice

I am using GCM-Notifications which are working really great! In my IntentService for the GCM-Notifications i use the following Code to create a notification: /** * */ private vo

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:

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"