'How to handle Fragment to not load again when coming from another fragment in Navigation Component in Android?
Scenario: I have 2 fragments ProductList and ProductDetail in my nav graph. And when i click on any product it opens the ProductDetail fragment using findNavController.navigate() method.
Problem: The problem is when I go back from ProductDetail to ProductList fragment, the ProductList fragment reloads again and it also calls the api to fetch products list, which I want to avoid.
If anyone knows the reason behind it or the solution to this particular issue please let me know in comments.
Solution 1:[1]
You should cache the fetch result locally, pull from the cache either during a fetch attempt or upon failure of a fetch attempt. This is a very common pattern on mobile.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | straya |