Navigation Architecture
框架来显示一些片段。不幸的是,每个片段都在创建一个新的活动。
Activity
具有
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
但他们没有太大的帮助,因为使用他们不会显示任何碎片后,第一次显示。
<?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>
家庭活动
打电话
NotificationActivity
作为
val intent = Intent(this, NotificationActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(intent)
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
请帮忙。