Avoid reply delay message

2

I'm developing an application that consumes, via REST, a third-party service. In some cases the service takes a long time to respond to me and, as the application is waiting for a response, a message appears giving the user the option to wait or close the application, as shown below:

This message appears mainly when I use 3G connection to consume the service.

Is there any way to avoid this message or increase response time indefinitely?

I did not use AsyncTask. I tried to make some adjustments but I did not succeed. So I would like to know if, under these circumstances, there is the possibility of avoiding the message. If using AsyncTask is the only way to avoid this scenario I would greatly appreciate recommending a material (or explanation) that is understandable to someone who does not have as much experience with Android as I do =)

From now on, I appreciate =)

    
asked by anonymous 02.12.2015 / 08:31

1 answer

0

I'm surprised you can not even consume a service without using AsyncTask .

Anyway. The options you have, aliases are the most common, is to use Volley or Retrofit

There's a lot of stuff around, like this one: link

and this link

Example with volley:

    final TextView tvMeuTextView = (TextView) findViewById(R.id.meu_textview);

    String url = "http://www.meu.server.com/meujson";

    JsonObjectRequest jsObjRequest = new JsonObjectRequest
            (Request.Method.GET, url, new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {
                    tvMeuTextView.setText("Resposta do servidor: " + response.toString());
                }
            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // em caso de erro na requisição, trata-o aqui
                }
            });

    //Preferencialmente crie um singleton para isso
    Volley.newRequestQueue(this).add(jsObjRequest);
    
02.12.2015 / 09:05