3

I'm working on a movie app, when the user first open the app I would fetch the most current popular movie data and populate it in my ListView. The initial fetch provide a list of movies, but only provide the basic information to fill a ListView (id, name, rating, release data, poster image url). To get the remaining data (run time, tagline, description, movie website, etc), I would have to fetch from /movies/{id} endpoint for each of the movies. Also, for a list of trailer, I would need to fetch from /movies/{id}/videos. Currently I'm fetching the movie detail data when they select the movie on the list using AsyncTask and then setting the Views with the data on the initial detail loading. I'm caching the data in a Content Provider and SQLite.

My questions are:

  1. How do I prefetch the data after getting the initial list of movie from the first fetch? I'm currently using an AsyncTask for the initial fetch, do I just start a list of AsyncTask in the middle of the initial task?
  2. Should I even be using AsyncTask for this situation or are there better alternatives? It seems like a SyncAdapter is a good idea for the initial fetch, but not sure what is best to use for the additional detail/trailer.

I just started working with Android a few weeks ago, so I don't know if I should even be doing things this way or if there are better solutions. Currently everything works, but I'm not sure if I'm going down the right path. I did read this, but wanted a more specific way on how to prefetch data.

Community
  • 1
  • 1
elguapo3
  • 31
  • 1
  • 3
  • Why you don't fetch everything at once? After finishing to fetch the initial data I understand that you already have the id to fetch the remaining data. About your second question, well I believe that it will depend on your business requirement. Usually, you will fill the list with some light amount of data and, once the user selects one item, you will load the details of that specific item. If the amount of data gets too heavy for the user connection, it'll take too long to fill the list once the app starts. I would recommend to load just the basic data and fetch the rest at the user's click. – E. Fernandes Jul 07 '15 at 00:04
  • An AsyncTaks is a separate thread, so it doesn't matter where or when you create it. I'd say you create an AsyncTask for the initial data, then another one for fetching the detail data, and another for the trailer if that's a separate data source. – Christine Jul 07 '15 at 00:06

1 Answers1

0

This sounds like a good use-case for Volley.

[1] - After you have done the initial fetch you can create your Volley RequestQueue and fire off a bunch of Requests (String/JSON) that you can then parse / cache the result as you already do. Volley is asynchronous, so you do not need to worry about where you add them to the queue, but the callbacks are performed on the UI thread so make sure they are reasonable (they may cause animation jank)

[2] - See above.

Flynny75
  • 1,593
  • 1
  • 11
  • 11