androidandroid-studioasynctaskloader

Should I use a Loader for each http connection or a single Loader for all it enough?


I am newbie of Android, trying to make a simple news feed app. I am using Asynctaskloader for background operations. For now, I am using a single Loader to connect different news sources. My question is should I define and run different loaders for each news source or a single loader will also handle it? I am asking because when the app opens it takes 5-10 seconds to load the news (So far I added only three news source), so could it be because of using a single Loader?


Solution

  • The problem with using a single loader's loadInBackground method to hit different data sources is that such access will be sequential within the associated thread. The total time to fetch and return the news from N sources will be the sum of each one's time, including delays or timeouts, assuming you wait until everything is downloaded to proceed with the presentation.

    You should consider more threads/loaders or another strategy (maybe fetch 1, show 1, fetch 2, add 2, etc) where the user doesn't get frustrated with the wait.