title: Not able to return the response from an API GET request in a android Kotlin function
body: <p>I'm currently trying to develop an android app in android studio in Kotlin. I use a RESTful API to GET/POST data to and from my app to a MSSQL database.</p>
  <p>In the android studio, I've made a function that sends a GET request to the API using Volley and returns the response from the API in JsonArray format.</p>
  <p>The problem I've encountered is that the response is empty(/skipped) which results in returning an empty JsonArray.</p>
  <p>The function looks as following:</p>
  <pre><code>1 fun apiGetRequest(context: Context, token: String?, id: String?): JsonArray {
  2     val queue = Volley.newRequestQueue(context)
  3     val url = &quot;http://**.**.*.**:**/****/****?token=$token&amp;id=$id&quot;
  4 
  5     var jsonArray = JSONArray()
  6 
  7     val jsonArrayRequest = JsonArrayRequest(url, { response -&gt;
  8         jsonArray = response
  9     }, {
  10        //Error listener
  11    })
  12    queue.add(jsonArrayRequest)
  13    return jsonArray
  14}
  </code></pre>
  <p>The URL used in this GET request works and returns the desired JsonArray in Postman. But in this function, the response is either empty or skipped. In debug mode it completely skips row 8 till 11 which results in returning an empty JsonArray.</p>
  <p>I've also tried to first break down the response in single JsonObjects and adding it to the JsonArray like this:</p>
  <pre><code>7 val jsonArrayRequest = JsonArrayRequest(url, { response -&gt;
  8         for(i in 0 until response.length()) {
  9             val jsonObject =  response.getJSONObject(i)
  10            jsonArray.put(jsonObject)
  11        }
  </code></pre>
  <p>But to no result.</p>
  <p>I have a feeling that the build-in multithreading in the android studio might be the cause of my problem. But I'm not sure.</p>
  <p>If anyone knows a fix or a solution to my problem, I would gladly hear it. Or even a push in the right direction is appreciated.</p>
  <p>Thanks in advance.</p>