Avoid response delay message

Asked

Viewed 164 times

2

I am developing an application that consumes, via REST, a third party service. In some cases the service takes time to answer me and, as the application is waiting for reply, a message appears offering the user the option to wait or terminate the application, as shown in the image below:

inserir a descrição da imagem aqui

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

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

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

From now on, thank you =)

1 answer

0

I’m surprised you can even consume a service without using Asynctask.

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

There’s plenty of stuff out there, like this: https://www.youtube.com/watch?v=V2nwFenaWRM

and this http://www.devmedia.com.br/android-retrofit-primeiros-passos-com-a-retrofit-api/31857

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);
  • 3

    Hello, @Androiderson. Could you include a small code demo in your reply? If these links become unavailable, there will still be code here. In addition to adding more value to stackoverflow.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.