public class PlayMusicService extends Service { // An interface object used by clients to communicate with the service. private final IBinder mBinder = new MyBinder(); @Override public void onCreate() { Toast.makeText(this, "Service Created", Toast.LENGTH_SHORT).show(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "Service Started", Toast.LENGTH_SHORT).show(); return Service.START_STICKY; // Service will be explicitly started and stopped as needed. } @Override public IBinder onBind(Intent i) { Toast.makeText(this, "Binding Service", Toast.LENGTH_SHORT).show(); return mBinder; } public class MyBinder extends Binder { PlayMusicService getService() { return PlayMusicService.this; } } public void onDestroy() { Toast.makeText(this, "Service Destroyed", Toast.LENGTH_SHORT).show(); } }