0

my question related only to the new Library from google Navigation Component library, so it's not related to the regular fragment like .addtobackstack and so on.

I will simplify what I wanna do, but my app has +30 fragment

we have a Parent fragment and child one Parent Fragment has tabs and recycler view and data comes from API. if I clicked on an RV item will Open child fragment. if I returned to the parent fragment I wanna it like it was, I don't wanna load data again.

my tests always reload again from the beginning, create views and then load the data, I wanna it like when we open new activity with intent, the parent activity still has his own views.

This is some of my code maybe I have an issue

   val host: NavHostFragment = supportFragmentManager
            .findFragmentById(R.id.main_activity_host_fragment) as NavHostFragment? ?: return 

class ParentFragment : Fragment() {
    var mEmail: String = ""
    var mPassword: String = ""
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        var rootView: View = inflater.inflate(R.layout.fragment_parent, container, false)

setupViews(rootView)
        loadDataFromServer()

        rootView.text_clickable_to_sign_up_from_sign_in.setOnClickListener {
            findNavController().navigate(R.id.child_frag_dest, null, null)
        }
        return rootView

    }}
...
Amr263
  • 143
  • 2
  • 8
  • Please use architectural patterns with Room (persistent storage) https://developer.android.com/jetpack/docs/guide you need to create Viewmodel/Repository and persistent storage for that. – Susheel Tickoo Sep 24 '19 at 12:07
  • Also to make sure you want to keep the state of RV persistent. You can look into caching the RV state https://developer.android.com/reference/android/support/v7/widget/RecyclerView.State. – Susheel Tickoo Sep 24 '19 at 12:33

0 Answers0