Add (not replace) fragment with navigation architecture component

后端 未结 6 1939
失恋的感觉
失恋的感觉 2021-01-31 02:14

I have an activity with a product list fragment and many other fragments and I am trying to use architecture component navigation controller.

The problem is: it replaces

6条回答
  •  半阙折子戏
    2021-01-31 02:37

    I was facing the same issue but in my case I updated my code to use livedata and viewmodel. when you press back the viewmodel is not created again and thus your data is retained.

    make sure you do the api call in init method of viewmodel, so that it happens only once when viewmodel is created

提交回复
热议问题