Jetpack Compose Navigation Deep Link вызывает дублирование действийAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Jetpack Compose Navigation Deep Link вызывает дублирование действий

Сообщение Anonymous »

Я пытаюсь показать уведомление, при нажатии на которое открывается ChatScreen. Он открывает ChatScreen, но начался как другое действие, поэтому в заднем стеке есть 2 MainActivity.
Я использую Compose Destinations , библиотека-оболочка для создания навигации.
Я пробовал режимы запуска SingleTop, SingleTask, SingleInstance, ничего не работает.
ChatScreen:
@Destination(deepLinks = [DeepLink(uriPattern = "https://mantools/chats")])
@Composable
fun ChatScreen(
navigator: DestinationsNavigator,
viewModel: ChatViewModel = hiltViewModel()
) {
//contents
}

Манифест










Уведомление
private fun showChatNotification(message: RemoteMessage) {
val data = message.data
showNotification(
data["title"] ?: "",
data["text"] ?: "",
TAG_CHAT,
Intent(Intent.ACTION_MAIN, "https://mantools/chats".toUri(), this.applicationContext, MainActivity::class.java)
)
}

fun showNotification(
title: String,
message: String,
tag: String,
intent: Intent
) {
val pendingIntent = getPendingIntent(intent)
val builder = NotificationCompat.Builder(context, GENERAL_CHANNEL_ID)
.setLargeIcon(context.getDrawable(R.mipmap.ic_launcher)?.toBitmap())
.setSmallIcon(R.drawable.app_logo)
.setColor(ContextCompat.getColor(context, R.color.primary))
.setContentTitle(title)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
notificationManager.notify(tag, System.currentTimeMillis().toInt(), builder.build())
}

private fun getPendingIntent(intent: Intent) = TaskStackBuilder.create(context).run {
addNextIntentWithParentStack(intent)
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
}


Подробнее здесь: https://stackoverflow.com/questions/753 ... e-activity
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»