0

What is the best way to navigate one activity to another activity using the Navigation component?

I am using this right now

fragmentLoginBinding.btnLogin.setOnClickListener(v -> {
            Navigation.findNavController(view).navigate(R.id.action_loginFragment_to_dashboardActivity);
            getActivity().finish();
        });

navigation.xml

<fragment
        android:id="@+id/loginFragment"
        android:name="com.example.navigation.LoginFragment"
        android:label="fragment_login"
        tools:layout="@layout/fragment_login">
        <action
            android:id="@+id/action_loginFragment_to_dashboardActivity"
            app:destination="@id/dashboardActivity"
            app:launchSingleTop="true"
            app:popUpTo="@id/navigation"
            app:popUpToInclusive="true" />
    </fragment>

0 Answers0