It takes a long time to receive results, even with AsyncTask's in parallel

1

I send a request to the server but it takes a long time to receive the result, I noticed that the AsyncTask that sends the location to the server every 1 second is in the way.

I noticed this after I changed it to 3 seconds, where I sent a new request that took from 1 to 3 seconds.

The code where AsyncTask is used is below:

   final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {


                    //Atualizar GeoLocalização
                    localizacao.setUsuario(motoqueiro.getId());
                    localizacao.setLatitude(location.getLatitude());
                    localizacao.setLongitude(location.getLongitude());

                    new GeoUpdateAsynctask().execute(localizacao);

            handler.postDelayed(this, APP_REFRESH_TIME * 1000);
        }
    }, APP_REFRESH_TIME * 1000);
}

I would like to suggest some other method that I can use in this case, since I use several AsyncTask in parallel.

    
asked by anonymous 13.08.2016 / 23:42

1 answer

2

You say that you are running multiple AsyncTask in parallel but it is not true.

AsyncTask , by default, runs in series on the same thread , even though they are different instances.

In order to run in parallel you will need to call the executeOnExecutor () , passing it an Executor .

new GeoUpdateAsynctask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, localização);
    
14.08.2016 / 00:19