Hi I am a beginner in Android and I am stuck in this problem.So this is what I am trying to do using a volley response object
private void parseJSONResponse(JSONObject response)
{
int a = jsonObject.getInt("xxx"); //get 1st parameter
String mid = jsonObject.getString("Movieid"); //get an id
String murl = genrate(mid); //send id to genrate method which returns another url
String x=createmovieJSON(murl);//method to create JsonObjectRequest object using the new url and return string.
info.add(new information(a,x)); //pass int and string for generating a card layout
}
createmovieJSON method is as follows:
public String createmovieJSON(String strurl)
{
final String[] str=(null); //str[0] contains null
RequestQueue requestQueue = Singelton.instantinate().getRequestqueue();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, strurl,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
str[0] = parseMovieResponse(response); //str[0] contains required string say'abc'
new Toastnotify(getApplicationContext(),str[0]);
}
},
new Response.ErrorListener(){...
});
requestQueue.add(jsonObjectRequest);
new Toastnotify(getApplicationContext(),str[0]);
return(str[0]); //str[0] contains null instead of abc
}
The 'final String[]' array is automatically created on correcting the error "Transform str into final one element array" in onResponse method.Why is it creating an array and not just make str final?(I tried doing that manually but it gives the same error).I know that it is a inner class and therefore I have to make it final but why array?
So how can I send the returned string in str[0] in onResponse back to the calling method in parseJSONResponse method?