0

I am working on a Music Player application and I have initialized my MediaPlayer instance in a service. I have implemented OnCompletionListener on the MediaPlayer instance. I am looking for a way to notify my activity that a track has finished its playback. I need this for updating a TextView in my activity which prints the present track name.

1 Answers1

0

If the activity wants to interact with the service directly, it can use the bindService() method to start the service.

This method requires a ServiceConnection object as a parameter which is called on the service start and when finishing its onBind() method. This method returns a IBinder object to the ServiceConnection.

This IBinder object can be used by the activity to communicate with the service.

When the binding process has finished, the onStartCommand() method in the service is called with the Intent object used for the bindService() method.

Further Informations: http://www.vogella.com/tutorials/AndroidServices/article.html#service_activitybinding

and

bind/unbind service example (android)

Community
  • 1
  • 1
Franzé Jr.
  • 1,194
  • 13
  • 20