从主要活动导航到片段
我使用导航图在片段之间导航。
现在,我在我的应用程序中实现了通知,因此,当我单击通知时,我将转到具有待处理意图的 MainActivity。
在 MainActivity 中,我验证用户是否已登录,并管理 putExtra 数据以了解导航到哪个片段。 问题是,activity_main.xml 似乎没有添加到导航图中,所以我没有 MainActivityDirections.actionMainActivityToFragment(argument)
我如何从活动导航到带有参数的一个片段?
Im using navgraph to navigate between fragments.
Now, i implemet notifications in my app, so, when i click on the notification im goingo to the MainActivity with pending intent.
In the MainActivity I verify if the user is loged in, and manage the putExtra data to know to which fragment navigate.
The problem is that the activity_main.xml doesn´t appear to add in the navgraph, so i don´t have MainActivityDirections.actionMainActivityToFragment(argument)
How can i navigate from the activity to one fragment with arguments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
对于这种情况有一个解决方案:
val navController = findNavController(R.id.nav_host_test)
navController.navigate(R.id.action_global_test)
首先,您需要访问 navController,其中 id 是从 Activity 中的视图 id 中获取的。
那么你需要创建一个全局动作,像这样(只注意动作):
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@+id/first_fragment">
<action
android:id="@+id/action_global_test"
app:destination="@id/second_fragment"
app:launchSingleTop="false"
app:popUpTo="@+id/mobile_navigation"
app:popUpToInclusive="true" />
<fragment
android:id="@+id/first_fragment"
android:name="com.grappim.myapplication.ui.home.HomeFragment"
android:label="@string/title_home"
tools:layout="@layout/fragment_home" />
<fragment
android:id="@+id/second_fragment"
android:name="com.grappim.myapplication.ui.dashboard.DashboardFragment"
android:label="@string/title_dashboard"
tools:layout="@layout/fragment_dashboard" />
</navigation>
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我实现了类似 @Grigoriym 的东西,但根据需要使用参数
MainActivity
和 orderDetialsFragment
I implemented something like @Grigoriym but with arguments as needed
MainActivity
and in the orderDetialsFragment