I followed this question to reuse volley service across diferent acitivies, but he just use the JSONOBject to GET and POST request, i need to return a JSONArray because i return more then 1 items with my request.
So i have something like this on my Volley Service:`public void
getDataVolley(final String requestType, String url){
Log.d("TRIED","TRIED0");
try {
Log.d("TRIED","TRIED");
RequestQueue queue = Volley.newRequestQueue(mContext);
JsonArrayRequest jsonArray = new JsonArrayRequest(Request.Method.GET, url,null, new Response.Listener
() {
@Override
public void onResponse(JSONArray response) {
Log.d("TRIED","TRIED2");
if(mResultCallback != null)
mResultCallback.notifySuccess(requestType, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("TRIED",error.toString());
}
});
jsonArray.setRetryPolicy(new DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(jsonArray);
}catch(Exception e){
Log.d("TRIED","TRIED4");
}
}`
So i use this service on my main activity like this:
Initialize
initPlants();
Log.d("RESULTCALL",mResultCallback.toString());
mVolleyService = new VolleyService(mResultCallback,this);
mVolleyService.getDataVolley(GETREQUEST,URL);
callback
void initPlants(){
mResultCallback = new IResult() {
@Override
public void notifySuccess(String requestType, JSONArray response) {
}
@Override
public void notifyError(String requestType,VolleyError error) {
Log.d("GJJJ","GJJJ1");
}
};
}
public void showToast(String message){
Toast toast = Toast.makeText(SimiliarPhotos.this,message, Toast.LENGTH_LONG);
toast.show();
}
The problem is i get a error in the second parameter on my response(volleyService), saying that it requires a JsonObject.
My IResult want a JSONObject and not a JSONArray