How to clear navigation Stack after navigating to another fragment in Android

First, add attributes app:popUpTo=’your_nav_graph_id’ and app:popUpToInclusive=”true” to the action tag. <fragment android:id=”@+id/signInFragment” android:name=”com.glee.incog2.android.fragment.SignInFragment” android:label=”fragment_sign_in” tools:layout=”@layout/fragment_sign_in” > <action android:id=”@+id/action_signInFragment_to_usersFragment” app:destination=”@id/usersFragment” app:launchSingleTop=”true” app:popUpTo=”@+id/main_nav_graph” app:popUpToInclusive=”true” /> </fragment> Second, navigate to the destination, using above action as parameter. findNavController(fragment).navigate( SignInFragmentDirections.actionSignInFragmentToUserNameFragment()) See the docs for more information. NOTE: If you navigate using method navigate(@IdRes int resId), you won’t get the … Read more

Sharing data between fragments using new architecture component ViewModel

Updated on 6/12/2017, Android Official provide a simple, precise example to example how the ViewModel works on Master-Detail template, you should take a look on it first.Share data between fragments As @CommonWare, @Quang Nguyen methioned, it is not the purpose for Yigit to make the call from master to detail but be better to use … Read more