我正在尝试使用谷歌的通用音乐播放器加上PlayerNotificationManager的代码来播放一些音乐,这不是原始代码的一部分(但属于ExoPlayer 2)。
我的服务通过来自PlayerNotificationManager的回调正确地执行startForeground(...)
playerNotificationManager.setNotificationListener(object : PlayerNotificationManager.NotificationListener {
override fun onNotificationStarted(notificationId: Int, notification: Notification?) {
startForeground(NOW_PLAYING_NOTIFICATION, notification)
}
override fun onNotificationCancelled(notificationId: Int) {
}
})一切似乎都很正常,直到我将应用程序的主要活动留给back,服务在几秒钟内被仁慈地杀死,如下所示:
2018-11-09 12:15:28.859 3680-3695/? W/ActivityManager: Stopping service due to app idle: u0a577 -1m19s332ms pl.qus.xenoamp2/pl.qus.xenoamp.xenoservice.MusicService通过使用以下命令正确启动服务
Util.startForegroundService(...)
那么,可能出了什么问题呢?
发布于 2019-11-26 01:12:10
在回调onNotificationStarted (或新引入的onNotificationPosted)中代替使用
startForeground(NOW_PLAYING_NOTIFICATION, notification)您必须使用提供的id
startForeground(notificationId, notification)https://stackoverflow.com/questions/53225105
复制相似问题