after setting listener on button I create navigationOnClickListener, which set startDestination to current fragment, after .navigate() it changes the destination to another fragment, but the view is not changed
onClickListener
navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment)
view.findViewById<Button>(R.id.fragment_button).setOnClickListener {
navController.navigate(R.id.Camera2VideoFragment_To_FirstFragment)
}
closeFragment()
private fun closeFragment()
{
closePreviewSession()
closeCamera()
parentFragmentManager.popBackStack()
updatePreview()
}
main.xml (navigation graph)
<?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/main.xml"
app:startDestination="@id/cameraFragment"
>
<fragment
android:id="@+id/cameraFragment"
android:name="com.example.camera2videotextureview.Camera2VideoFragment"
android:label="Camera2VideoFragment"
tools:layout="@layout/fragment_camera2_video">
<action
android:id="@+id/navigateToSecondFragment"
app:destination="@id/firstFragment" />
</fragment>
<fragment
android:id="@+id/firstFragment"
android:name="com.example.camera2videotextureview.FirstFragment"
android:label="FirstFragment"
tools:layout="@layout/fragment_first" />
</navigation>
Main fragment is the camera fragment using Camera2 API. FirstFragment is just blank kotlin class where layout contains just one TextView.
EDIT: Now I have edited onClickListener, I am not able to change the current view, I need to use popBackStack on current fragment, but donot know how.