Skip to content Skip to sidebar Skip to footer

Send Data From Service To Bound Activity Periodically

I have an Activity that starts and binds to a service. It sends an intent with a List of data and the service is responsible for periodically updating that data. This is done in th

Solution 1:

I suggest you check EventBus. it will allow you to send events like local broadcast receiver. And from that in activity you can listen specific event and display result. you can even use interface to get callback from service also.

Without any library you can achieve this with LocalBroadcastManager. http://developer.android.com/reference/android/support/v4/content/LocalBroadcastManager.html

Solution 2:

For this problem, you can use a ResultReceiver. If both the service and activity share the same ResultReceiver object then you can "push" data to the Activity from the Service using the "send(int, Bundle)" method and on the Activity side receive it with "onReceiveResult(int, Bundle)".

ResultReceiver | Android reference

Post a Comment for "Send Data From Service To Bound Activity Periodically"