2

I am working around to preserve the view (without storing as local variable) of fragment and in current Navigation Component it looks certain that onDestroyView() is called, I want to avoid calling onDestroyView() with Android Navigation but there is no such method that behaves like there was in FragmentTransaction.add() in our vanilla Fragment.

In Navigation Jetpack we have:

FragmentNavigator.navigate() which makes use of fragmentTransaction.replace() like this :

ft.replace(mContainerId, frag);

Why there is no option of ft.add() method? If there is a workaround, how can we do it?

Is it like the concept of ft.add() is being discontinued?

halfer
  • 19,824
  • 17
  • 99
  • 186
erluxman
  • 18,155
  • 20
  • 92
  • 126
  • Can you explain your use case? Why `add` makes sense for you and `replace` doesn't? Navigation library helps you *switch* between destinations. `add` doesn't really fit that description. Perhaps a screenshot would help. – Eugen Pechanec Mar 13 '19 at 16:03
  • I want to go from screen A from screen B to get a location, when the fragment B passes back the location to Screen A, the screen A should animate the marker from older position to the new position recently returned from the screen B , doing so with fragment navigation the view of Scren A gets recreated in onCreateView() I want to avoid recreating the view. – erluxman Mar 13 '19 at 17:16

0 Answers0