我有一个媒体播放器,我在服务中实现了它,我从我的 android 应用程序中的一个活动中调用 startSerivce(),我还显示来自我的服务的通知以保持用户更新。
这是问题所在:当我按下返回按钮并关闭活动并关闭手机屏幕时,音乐播放器服务将播放 1~2 分钟,然后它将关闭服务并停止音乐。
我的活动代码:
public void onCreate(Bundle savedInstanceState) {
//some code above
Intent intentMPLS = new Intent(Splash.this, MediaPlayerLocalService.class);
startService(intentMPLS);
//some code below
}
在我的服务中,我有以下 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;
}
如何防止 android 杀死我的服务?
注意:我的 MediaPlayer 是 Vitamio,以防万一出现问题。