Я реализовал Navigation Architecture
Framework для отображения нескольких фрагментов. К сожалению, каждый фрагмент создает новую деятельность.
Итак, я начал Activity
с intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
и intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
флаги, но они не очень помогли, поскольку их использование не покажет ни одного фрагмента после показа только в первый раз.
nav_graph.xml
<?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"
android:id="@+id/notification_nav_graph"
app:startDestination="@id/openingNotificationFragment">
<fragment
android:id="@+id/standByScreenFragment"
android:name="com.emaz.android.ui.notification.standby.StandByScreenFragment"
android:label="StandByScreenFragment" />
<fragment
android:id="@+id/welcomeNotificationFragment"
android:name="com.emaz.android.ui.notification.welcome.WelcomeNotificationFragment"
android:label="WelcomeNotificationFragment" />
<fragment
android:id="@+id/openingNotificationFragment"
android:name="com.emaz.android.ui.notification.ingress..OpeningNotificationFragment"
android:label="OpeningFragment" />
<fragment
android:id="@+id/closingNotificationFragment"
android:name="com.emaz.android.ui.notification.ingress..ClosingNotificationFragment"
android:label="ClosingNotificationFragment" />
</navigation>
HomeActivity
Вызов NotificationActivity
как
val intent = Intent(this, NotificationActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(intent)
NotificationActivity
И называть фрагменты как
notification_container.visibility = View.GONE
fragment_layout.visibility = View.VISIBLE
val navController = Navigation.findNavController(this, nav_host_fragment.id)
navController.popBackStack()
Log.e("nav", "${navController.currentDestination} and $resId < ResourceId")
navController.navigate(resId, null)
Я видел, как меняется resId
, но не мог видеть на экране.
Пожалуйста, помогите.