我在应用程序中的某个位置启动一项服务,并从那里创建通知.我将应用程序放到后台,然后点击通知
我希望发生的事情:应用程序以与其相同的状态进入前台,就像我按下了设备上的"查看所有后台应用程序"按钮并将其选中一样.
实际情况:我进入应用程序的主屏幕.
我梳理了一堆线索,try 了不同的方法.每次我更改任何东西,当我按下通知时,应用程序根本不会打开.
class TestService : Service() {
private lateinit var notificationBuilder: NotificationCompat.Builder
...
private fun createNotification(): Notification {
...
notificationBuilder = NotificationCompat.Builder(this, channelId)
notificationBuilder
.setSmallIcon(R.drawable.ic_notif)
.setContentTitle(titleText)
.setContentText(getFormattedTime())
.setOnlyAlertOnce(true)
.setContentIntent(PendingIntent.getActivity(this, 1, Intent(this, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE))
.setOngoing(true)
...
return notificationBuilder.build()
}