Volley and AsyncTask

Viewed 39850

I read a post about Volley and I know it's great networking library. But I couldn't understand one thing.

All requests are Async Task or not?

When I want to send asyncTask request using Volley do I need put Volley request in AsyncTask? or should I just call Volley Request if it is already AsyncTask request?

 private class MyClass extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
           // do Volley request
        }
}

Is this right approach?

4 Answers

The whole point of introducing Volley library was to make sure user doesnt have to worry about all the "obvious" stuff while sending a network request. This means that volley takes care of the following on its own

  • Switching Background thread
  • Transparent disk and memory response
  • Multiple concurrent network connections. etc

To answer your question- You don't need to worry about switching to background thread, Volley takes care of this on its own. Also once the request is completed the success or failure callback is invoked on the main thread.Hence with Volley developer need not worry about switching threads

This tutorial here gives a good step by step explanation of Working with Volley Library

Related