I'm sorry if the title is ambiguous as I don't know how to describe my problem in a short way.
I'm using ViewPager
with FragmentStatePagerAdapter
to display a list of posts of a forum's thread. Each page of the ViewPager
is corresponds to a page of the thread. There are some types of link that lead to the thread without specifying the page, for example: showthread.php?t=12345&goto=newpost
, which means that I can only get current page and total pages after loading that link. Assume that the link will lead to page 5 and there are 10 pages, my current flow is:
ViewPager
has 1 page initially- Load the link and notice that current page is 5 and total pages is 10
- Update total pages and notify
ViewPager
usingviewPager.getAdapter().notifyDataSetChanged();
. This causesViewPager
to load page 2 automatically - Jump to page 5 using
viewPager.setCurrentItem(page);
. This causesViewPager
to load page 4, 5 and 6 automatically
So I end up with 2 redundant requests (for loading page 2, and page 5 again (the first time is through the link). Is there any ways to avoid this?