Android Jetpack Navigation Component Not Preserving Fragment State on Back Press
I'm currently implementing the Android Jetpack Navigation component for my app, but I'm running into an issue where the state of my fragments is not being preserved when navigating back to them. I have a setup where I navigate from `FragmentA` to `FragmentB`, and then back to `FragmentA` using the back button. However, every time I return to `FragmentA`, it is recreated, resulting in the loss of the data entered in `EditText` fields. I've tried using `savedInstanceState` to restore the state in `onCreateView`, but it seems like the fragment is being completely recreated, and the `savedInstanceState` is not being utilized. Here's a snippet of my implementation: ```kotlin class FragmentA : Fragment() { private var inputText: String? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.fragment_a, container, false) val editText = view.findViewById<EditText>(R.id.editText) if (savedInstanceState != null) { inputText = savedInstanceState.getString("inputText") editText.setText(inputText) } editText.addTextChangedListener(object : TextWatcher { override fun afterTextChanged(s: Editable?) { inputText = s.toString() } override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} }) return view } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) outState.putString("inputText", inputText) } } ``` I also checked that Iām using the latest version of the Navigation component (2.4.1). The issue seems related to how the navigation graph is set up, as `FragmentA` is added to the back stack when navigating to `FragmentB`. Any insights on how to preserve the state of `FragmentA` when navigating back would be greatly appreciated!