我已经根据此链接在我的应用程序中集成了ExoPlayer。
我在createCurrentContentIntent()中添加了一个待处理的意图(pending intent)。
return PendingIntent.getActivity(
context, 0,
Intent(context, MyActivity::class.java), 0
)
我遇到了一个问题。我开始播放音频,播放器通知也出现在状态栏中。我的要求是即使应用程序在后台,也要播放音频。因此,我没有在onStop()中释放播放器。我已经在onDestroy()中添加了以下代码。
override fun onDestroy() {
playerNotificationManager?.setPlayer(null)
player?.stop()
player?.release()
player = null
super.onDestroy()
}
如果我在播放器播放时手动从后台杀死应用程序,则通知不会消失。因此,如果我点击通知,它将由于 MyActivtity 已经不存在而崩溃并显示 NullPointerException。
有人能否就此提供解决方案?