【发布时间】:2023-03-12 09:20:02
【问题描述】:
当来到 HomeFragment(startDestination) 时如何清除所有堆栈,当用户通过导航组件按下 homeFragment 时,我想关闭应用程序。
<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"
app:startDestination="@+id/homeFragment">
<fragment android:id="@+id/homeFragment"
android:name="ui.fragment.home.HomeFragment"
tools:layout="@layout/fragmet_home"
android:label="HomeFragment"
app:launchSingleTop="true"
app:popUpToInclusive="true">
<action android:id="@+id/action_homeFragment_to_notificationFragment"
app:destination="@id/notificationFragment"
app:popUpTo="@+id/homeFragment"
app:enterAnim="@anim/pop_enter"
app:exitAnim="@anim/pop_exit"
app:popEnterAnim="@anim/right_in"
app:popExitAnim="@anim/right_out"/>
</Fragment>
<fragment android:id="@+id/notificationFragment"
android:name="ui.fragment.notification.NotificationFragment"
tools:layout="@layout/fragment_notification"/>
</navigation>
【问题讨论】:
标签: android kotlin navigation android-jetpack onbackpressed