Volley works in an asynchronous way, it means that you can't know when the response will arrive from your webservice. It will works on separate thread rather than UI thread.
So the outside block of code will get executed irrespective of the Volley
response.
If you need the string in your function you should probably create a method and call it when you have the result.
Here is an example:
public void onResponse(String response) {
try {
JSONObject json = new JSONObject(response);
JSONArray jArray = json.getJSONArray("results");
Log.d(TAG, "readJSON: " + jArray.length());
JSONObject json_data = jArray.getJSONObject(0);
medicine_description = json_data.getString("description");
passdata(medicine_description); //create method to pass data
Log.i("THIS ONE IS FINE",medicine_description);
/*for(int i=0; i<jArray.length(); i++){
JSONObject json_data = jArray.getJSONObject(i);
medicine_description = json_data.getString("description");
Log.i("log_tag",medicine_description);
}*/
} catch (JSONException e) {
e.printStackTrace();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…