


To call send() on Messenger supplying the Message object as To be send.Whenever an event needs to be send to the activity,we need Service.Service will populate Message object with whatever data needs To it.Messenger is parcelable ,and can therefore be put intoĪn Intent extra,so your activity can pass this Messenger to the Messenger references to a Handler, which others can use to send messages Integrated using this library which is explained here. You can have the service raise events which activities or fragmentsĬan listen for and respond to using Event Bus.Event Bus can be Method on the PendingIntent to notify the activity via PendingIntent to the service.The service, in turn, can call send() Therefore be put into an Intent extra,your activity can pass this

Int, Intent) callback.Since a PendingIntent is Parcelable, and can Send result data back to your activity inside onActivityResult(int, PendingIntent.For that we can use createPendingResult() which createsĪ new PendingIntent object which you can hand to service to use and to You can also use Pending Intent,Event Bus or Messenger for real time communication from service with activity.Ĭheck out my blog post at below link which covers all these approaches with example-Ĭommunication between service and Activity can be done using In the meantime, if the app goes in background, then because the service is started the song will continue to play without providing updates of the current position of the song. The started part of the service will play the song in the background and the bound part of the service will provide updates of the current position of the song being played. My suggestion would be to create such a service. In android you can create a service which is started and bound at the same time. Bound Service : Used for long running task where there is a client/server relationship between the invoker (in this case the app) and the service.So for example if you want to upload a video in background and only intimate the user that the upload was a success or a failure, then you use a started service and use notifications to inform the user of the status (success or failure)

