Play music using MediaPlayer in Service

This post describes an example of a music player which plays the audio file picked. The MediaPlayer runs in Service class which continues to run even when app is closed. The MediaPlayer is controlled by the Activity bound to the Service, which unbinds when the Activity exits and binds again when the Activity starts. Create … Read more

Communicate with bound Service Example

This post describes how to bind to a Service and unbind a Service on Button click. Create your layout in activity_main.xml. Add a TextView for displaying date, a Button for binding to service, and another button for unbinding from Service, and a Button to update time. Create a java file, TestService.java and add following code. … Read more

Android Started Service Example

This post describes how to start a Service and stop a Service on Button click. Create your layout in activity_main.xml. Add a TextView for displaying date, a Button for starting service, and another button for stopping Service. Create a java file, MyService.java and add following code. In AndroidManifest.xml add the Service class. In MainActivity.java bind … Read more

Android Bound Service Example

This post describes how to bind to a Service and unbind a Service on Button click. Create your layout in activity_main.xml. Add a TextView for displaying date, a Button for binding to service, and another button for unbinding from Service. Create a java file, MyService.java and add following code. In AndroidManifest.xml add the Service class. … Read more