Volley and processing data returned in background on Android Volley and processing data returned in background on Android multithreading multithreading

Volley and processing data returned in background on Android


Please read my reply until the end

If you want to 'process' data in the same thread as the request, you should have subclasses of Request (or JsonRequest) and implements parseNetworkResponse(NetworkResponse response)

Example :

public class TotoRequest extends JsonRequest {    @Override    protected Response parseNetworkResponse(NetworkResponse response) {        try {            String jsonString =                    new String(response.data, HttpHeaderParser.parseCharset(response.headers));            JSONObject jsonObject = new JSONObject(jsonString);            // Process data here        } catch (UnsupportedEncodingException | JSONException e) {            return Response.error(new ParseError(e));        }    }}

This is the reply to your question but I think it's not what you actually want.

It's probably safer to either process your data in the main thread if your data is small.

If your data is important, or if you want to insert/update it in a database you should simply continue doing what you are doing.

Also, I would recommend you to use an AsyncTask instead of a thread.