I have a mediaplayer which I implemented it inside service and I call startSerivce() from an activity in my android app, also I show a notification from my service to keep user updated.
Here is the problem : When I press back button and close activity and turn of the mobile's screen the musicplayer service will play for 1~2 minutes then it will close the service and stops the music.
my activity code :
public void onCreate(Bundle savedInstanceState) {
//some code above
Intent intentMPLS = new Intent(Splash.this, MediaPlayerLocalService.class);
startService(intentMPLS);
//some code below
}
and inside my serivce I have following for startForground :
public int onStartCommand(Intent intent, int flags, int startId) {
startForeground(PlayerNotification.NOTIFICATION_ID,
PlayerNotification.getInstance(this, global).createServiceNotification(true));
//The PlayerNotification is cusotmized class to show notification
return START_STICKY;
}
How can I prevent android to kill my service?
note : my MediaPlayer is Vitamio just in case if Vitamio is the problem.