0

I have a ViewPager backed by a FragmentStatePagerAdapter. The app is a single Activity app, with fragments for each "page". Currently I'm using the ViewPager to display Categories of Products, and each Category will contain a ListView (or RecyclerView) that lists all the products. Once a user taps on a product, the viewpager fragment is replaced by the ProductDetailsFragment. Which is all fine and dandy but when the user presses back, it reloads all the Category fragments. Is there anyway to avoid that? The issue is that if a user had to paginate over 3 pages they'll want to maintain their scroll state.

StackOverflowed
  • 5,854
  • 9
  • 55
  • 119

1 Answers1

0

You should use this

  fragmentTransaction.add(android.R.id.content, fragment, Fragment.class.getSimpleName());
  fragmentTransaction.addToBackStack(Fragment.class.getSimpleName()).commit();
Dmitriy Puchkov
  • 1,530
  • 17
  • 41