0

Hi i have a volley request and i want to stop continue run app for get complete json from server and i want to use this tutorial Volley - http request in blocking way

but i do not understand where i must put , future, future

where i must put volleyRequestQueue.add(request);

where i must put

 try {
JSONObject response = null;
while (response == null) {
    try {
        response = future.get(30, TimeUnit.SECONDS); // Block thread, waiting for response, timeout after 30 seconds
    } catch (InterruptedException e) {
        // Received interrupt signal, but still don't have response
        // Restore thread's interrupted status to use higher up on the call stack
        Thread.currentThread().interrupt();
        // Continue waiting for response (unless you specifically intend to use the interrupt to cancel your request)
    }
}
// Do something with response, i.e.
new SignUpResponseListener().onResponse(response);
} catch (ExecutionException e) {
// Do something with error, i.e.
new MyErrorListener().onErrorResponse(new VolleyError(e));
} catch (TimeoutException e) {
// Do something with timeout, i.e.
new MyErrorListener().onErrorResponse(new VolleyError(e));
}

and my volley request is :

  JsonArrayRequest movieReq = new JsonArrayRequest(url,
    new Response.Listener<JSONArray>() {
      @Override
      public void onResponse(JSONArray response) {
      for (int i = 0; i < response.length(); i++) {
      try {
      JSONObject obj = response.getJSONObject(i);
      int lage = (obj.getInt("flage"));

       Toast.makeText(send_new_content.this, "flage "+lage, Toast.LENGTH_SHORT).show();
         } catch (JSONException e) {
             e.printStackTrace();

           }}}
         }, new Response.ErrorListener() {
         @Override
        public void onErrorResponse(VolleyError error) {
         }});
     AppController.getInstance().addToRequestQueue(movieReq);
Community
  • 1
  • 1
nazanin
  • 729
  • 1
  • 6
  • 13
  • You don't need a Future and you shouldnt blocks the UI... and you already have the request queue, so what is the actual issue? – OneCricketeer Feb 25 '17 at 18:41
  • i want to stop thread to get complete addres urls images from server – nazanin Feb 25 '17 at 18:43
  • But why? Showing a dialog or progress bar is the correct Android UI design – OneCricketeer Feb 25 '17 at 18:44
  • can you Showing a dialog or progress bar is the correct Android UI design help me i am amature – nazanin Feb 25 '17 at 18:45
  • I'm simply pointing out that "pausing" the UI is a bad design in any system. What would you think if you were to go to Stackoverflow search page, type something and just sit and wait for 30 seconds for anything to happen? – OneCricketeer Feb 25 '17 at 18:49
  • ok i search pausing in site thanks – nazanin Feb 25 '17 at 18:51
  • That's not what I meant at all... If you do anything online, you expect some type of feedback, right? Otherwise, user won't know if anything is actually going on – OneCricketeer Feb 25 '17 at 18:54

1 Answers1

0

i want to stop continue run app

I understand you want that, but don't. It's bad user experience.

You can rather make new ProgressDialog() and show/hide when the request happens/completed

You already passed the Response Listener fine in the movieReq, so maybe you should be more focused on parsing the JSON array into some Java objects and loading an Adapter to display on a ListView.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245