带有Android导航组件的通知点 击监听器

问题描述 投票:0回答:1

我在活动中使用此代码来更改当前目的地。可悲的是,它也重新创建了主机活动。

val pendingIntent = NavDeepLinkBuilder(this)
            .setComponentName(MainChatActivity::class.java)
            .setGraph(R.navigation.graph_chat)
            .setDestination(R.id.chatViewFragment)
            .setArguments(bundleOf(ChatViewFragment.DIRECT_ARGUMENT to notificationBox.mDirectPresenter))
            .createPendingIntent()

[我想要一种避免重新创建MainChatActivity或在重新创建时停止再次调用其观察者的方法。

android android-notifications android-pendingintent android-architecture-navigation
1个回答
0
投票

此处的解决方法,如果您希望每个值仅将LiveData触发一次,则可以使用SingleEvent。这是关于如何实现它的很好的文章https://proandroiddev.com/livedata-with-single-events-2395dea972a8

© www.soinside.com 2019 - 2024. All rights reserved.