Aadi
Aadi

Reputation: 77

Navigation Architecture Component: How to use same Fragment while navigation

I have 3 fragments navigation each of them by 'Navigation.navigate' making network API to reload and viewpager to set again. I wanted to use the same fragment as it is, which was open already.

I am using the "Navigation Architecture Component", and I am using Navigation.navigate method

Upvotes: 2

Views: 707

Answers (1)

Alireza Ahmadi
Alireza Ahmadi

Reputation: 5348

If you create your fragment each time a navigation happens you can instead use show() and hide() methods of the fragment, so whenever one of them is the visible show it and hide the other two and another way around. But if your problem is reloading data maybe you should consider other options. Like using ViewModel to store the data of the fragment. please provide more info and publish your code so we can help you better.

Upvotes: 1

Related Questions