Как показать пуш при уничтожении приложения?

Необходимо показать пуш если пользователь убивает процесс приложения.

Код по созданию нотификации не отрабатывает в onDesttroy() у Activity.

val notification = Notification("HOHOHO", "HAHAHAH", NotificationType.CUSTOM)
NotificationHandler.sendNotification(this, notification)

fun sendNotification(
    context: Context,
    notification: Notification,
) {
    val intent = Intent(context, DriverActivity::class.java).apply {
        action = Intent.ACTION_VIEW
        flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
        notification.deeplink?.let {
            data = Uri.parse(it)
        }
    }
    val pendingIntent = PendingIntent.getActivity(
        context,
        MessagingDriverService.NOTIFICATION_CODE,
        intent,
        PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
    )

    val defaultSoundUri: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
    val notificationBuilder = NotificationCompat.Builder(
        context,
        MessagingDriverService.CHANNEL_ID
    )
        .setContentTitle(notification.title)
        .setContentText(notification.message)
        .setAutoCancel(true)
        .setSound(defaultSoundUri)
        .setPriority(NotificationCompat.PRIORITY_MAX)
        .setSmallIcon(R.drawable.ic_launcher_foreground)
        .setContentIntent(pendingIntent)

    val notificationManager =
        context.getSystemService(FirebaseMessagingService.NOTIFICATION_SERVICE) as NotificationManager

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        notificationBuilder.setChannelId(context.packageName)
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val channel = NotificationChannel(
            context.packageName,
            context.resources.getString(R.string.app_name),
            NotificationManager.IMPORTANCE_HIGH
        )
        notificationManager.createNotificationChannel(channel)
    }

    notificationManager.notify(
        MessagingDriverService.NOTIFICATION_CODE,
        notificationBuilder.build()
    )
}

Ответы (0 шт):