There are three fragments that change between themselves in FrameLayout , while instances of fragments are preserved. How can I run the getData() method once when I first create a fragment and then not execute it after the fragment is restored?

Since the getData() method refers to elements, I cannot add it to onCreate()

As an option, you can add a boolean variable to the savedInstanceState , but is this the right solution?

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) ... getData() ... } 
  • 2
    in getData (), check data for null and do not fill in if it already exists - pavlofff

0