I am working on a News reading Android application. Whenever the user clicks on any News List item, I open NewsDetailActivity
and thus want to index that news. This activity contains a ViewPager
so that the user can swipe and keep on reading more news. Since the number of articles the user can swipe are not fixed, I have used FragmentStatePagerAdapter for the implementation.
Now according to the Official Google documentation
Regarding fragments: You structure fragments in the same way as the activity in the example above. But because fragments may execute many times within an activity, or there may be multiple fragments, you should take care to make the API call only once. Here are some guidelines: If the activity calls the API, then don't call the API again from any fragment within the activity. If the activity doesn't call the API, and you want a fragment to call it instead, then make sure only one fragment calls the API and only one time.
According to the official doc, if you are using fragments, then only one of the fragments should call the indexing API. However in my case, every swipe creates a new fragment
in the activity
. And each fragment
contains a news article that I would like to index. So how should my implementation be like? Right now I can think of only two solutions here
Which is the better approach of the two? Or is there some other approach which can work out well in my case.
As long as you call the API for a new content (not the same content over and over) it is fine. You can have multiple API calls each for different content.
Cheers,
MB