6

They tell everywhere that we should use ASyncTaskLoaders because they are very good at not blocking the UI thread. And there is Volley to use now.

I guess we cannot use both of them because Volley does backgrounding on its own. What do you think? Which one is better?

Itai Hanski
  • 8,540
  • 5
  • 45
  • 65
tasomaniac
  • 10,234
  • 6
  • 52
  • 84
  • [check out this](http://androidcustomviews.com/portfolio/volley-easy-fast-networking-for-android/) both have different benefits you have to find yours. – Girish Bhutiya Aug 07 '13 at 06:37
  • The link compares Volley with ASyncTask. Volley is way better then AsyncTask. That is known. But what about the Loader interface? We cannot use Loader interface if we use Volley, can we? – tasomaniac Aug 07 '13 at 12:27
  • in upper url check kpbird tutorial they have show progress dialog. – Girish Bhutiya Aug 07 '13 at 13:34
  • Not related at all. It is just a basic tutotial – tasomaniac Aug 07 '13 at 22:00
  • 1
    I think Volley is better for static content loading. But for long live download operation(like large file or streaming ), it's better to use Ansync Task since you could control all the stuff like locking, I/O, etc. You could watch the video in Google I/O 2013. There's a little comparison in the first couple of mins of the lecture . – Nevin Chen Oct 29 '13 at 09:51

5 Answers5

3

These 2 technologies are different and hardly comparable. They have different purposes and can also work together. You could for exemple implement a Loader that uses Volley to load the data and inherits directly from Loader (not AsyncTaskLoader, because Volley handles the threading as well).

Main advantages of using Loaders:

  • Lifecycle is synchronized with the Activity/Fragment lifecycle automatically
  • Data and loading state is not lost on configuration change
  • The loader monitors changes and pushes new results automatically to the client fragment/activity.

Main advantages of using Volley:

  • High performance network stack
  • Automatic disk cache that respects the HTTP server policy
  • Powerful cancelation mechanism.

You can combine both to get both sets of advantages or you can use Volley without loaders with its simple API.

BladeCoder
  • 12,779
  • 3
  • 59
  • 51
2

I've been using Volley for a month now and I have to say that I'm very satisfied. It really does help a lot not to have to worry about threading implementation details. So far both general networking and remote image loading have been working great.

It's not that there are no issues, but so far they have been minimal.

Itai Hanski
  • 8,540
  • 5
  • 45
  • 65
1

You better ask like this volley vs Async vs RxJava

You can use this RXJava for background thread, but for better efficiency in calling restful services Volley is highly recommended, also very less coding required compare to async task loaders !

LOG_TAG
  • 19,894
  • 12
  • 72
  • 105
1

Here is a writeup on current Android best practices. It discusses the use of Volley and RXJava: https://github.com/futurice/android-best-practices

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
0

You can combine both, to get both advantages.

In your activity (main thread) you call your API with Volley. With a simple interface mechanism, you callback your main thread when the data is available. Then you forceLoad() your AsyncTaskLoader with the fresh data from Volley. In your AsyncTaskLoader you hydrate all your activity's container. They will be automatically loaded when data is available.

With this approch you combine Automatic disk cache of Volley, and Automatic synchronization of Loader.