On startup i call bindService in onCreate()
of my first activity so i can access my mediaplayer object which is a static object.
public static void bindMusicService(Context c){
/*mediaPlayerServiceIntent binds our connection to the MediaPlayerService. */
mediaPlayerServiceIntent = new Intent(c, MediaPlayerService.class);
c.bindService(mediaPlayerServiceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
mServiceIsBound = true;
Log.i("Main","Service is bound!");
}
Now when i click a song in my activity i call:
ContextCompat.startForegroundService(context, intent);
But what if the user doesn't click on a song and just closed the app? Do i still need to call unbindService();
in onPause()
?
Because when the user does click on a song, it will show a notification which song is playing and when the app is moved to the background or swiped away and unbind is called, the notification won't work anymore.