0

I'm developing an app which will show some items in RecyclerView by fetching JSONs from a web service. If a user scrolls at the end of the list, more data should be fetched. For the UI, I've implemented EndlessScrollListener, but I'm not sure what would be the right option for fetching actual JSON with a proper page index (e.g. http://some.service/data&page=1). To read data from an HTTP resource, I decided to use the Volley library. If I use just Volley itself it will be a problem to handle the onConfigurationChanged event manually.

I know that AsyncTaskLoader can help me to solve my problem, but it looks like it was designed to fetch data periodically. In my case I need to load data on demand (when user scrolls down).

I also thought about implementing sync adapter to fetch data, cursor loader and content provider to save/read data in offline mode, but it looks hard for me now, because I'm an Android novice.

What can you suggest?

I'm mostly interested in architectural part of solution.

mc01
  • 3,750
  • 19
  • 24
Yuriy Seredyuk
  • 1,643
  • 2
  • 15
  • 18
  • The correct way is simply to explain but difficult to implement, I'll just explain in this comment. 1) HTTP calls do not reply back to activity, they simply write to a local storage cache area. 2) activity.onStart load from and subscribe to the local storage cache and update when the data gets changed. 3) activity.onStop unsubscribe from the local storage. There're a billion ways of doing it an half a million libraries or frameworks. Good luck. – Budius May 26 '16 at 16:04
  • @Budius thank you. Can you also suggest at least one example with some particular libraries, classes etc.? Therioticaly is more clear, but can you show some example? – Yuriy Seredyuk May 26 '16 at 16:21
  • this guy gives an awesome talk covering the bases of it: https://www.youtube.com/watch?v=xHXn3Kg2IQE – Budius May 26 '16 at 16:23

1 Answers1

0

Deserialisation of json sometimes is also hard task so what you need to do is make request with volley then on result you have json string, then in async task you make deserialisation to local Object that has structure you need and only then setup view and attach final data to it. If you load list and want to make it load on scroll here is sample

Community
  • 1
  • 1
Stepan Maksymov
  • 2,618
  • 19
  • 31