isUserRegistered
在中为true
SharedPreferences
//declared at the top in onCreateView() of fragment
val prefs = appContext!!.getSharedPreferences("expense_prefs", Context.MODE_PRIVATE)
val editor = prefs.edit()
editor.putBoolean("isUserRegistered", true)
editor.apply()
findNavController().navigate(R.id.action_getStartedFragment_to_homeFragment)
//in the same onCreateView() of fragment1
val isUserRegistered = prefs.getBoolean("isUserRegistered", false)
if (isUserRegistered)
findNavController().navigate(R.id.action_getStartedFragment_to_homeFragment)
下面是我的导航文件,其中我还添加了
app:popUpToInclusive="true"
在两种导航中。
<?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/navigation"
app:startDestination="@id/getStartedFragment">
<fragment
android:id="@+id/getStartedFragment"
android:name="net.softglobe.expensemanager.GetStartedFragment"
android:label="fragment_get_started"
tools:layout="@layout/fragment_get_started" >
<action
android:id="@+id/action_getStartedFragment_to_homeFragment"
app:destination="@id/homeFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/homeFragment"
android:name="net.softglobe.expensemanager.HomeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home" >
<action
android:id="@+id/action_homeFragment_to_getStartedFragment2"
app:destination="@id/getStartedFragment"
app:popUpToInclusive="true" />
</fragment>
</navigation>
isUserRegistered
是真的。请帮助解决问题。如果没有解决方案,请至少向上投票以获得更广泛的观众。