I get the message: "the application may be doing too much work on its main thread", using Retrofit with Android [closed]

3

Good I have this method to get the response:

public void cargarFilas(String filtro){

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .addNetworkInterceptor(new StethoInterceptor())
            .build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://10.0.2.2/api/"+filtro+"/")
            .addConverterFactory(GsonConverterFactory.create())
            .client(okHttpClient)
            .build();

    apiService= retrofit.create(ApiService.class);
    Call<Usuario_Fila> call = apiService.list(txtBuscar.getText().toString());
    call.enqueue(new Callback<Usuario_Fila>(){

        @Override
        public void onResponse(Call<Usuario_Fila> call, Response<Usuario_Fila> response) {
            if (response.body() != null && response.isSuccessful()) {
                datos = response.body();
                Usuario_Adaptador_Busqueda adaptador = new Usuario_Adaptador_Busqueda(Usuario_BusquedaActivity.this, datos.getFila());
                list.setAdapter(adaptador);
            }
        }

        @Override
        public void onFailure(Call<Usuario_Fila> call, Throwable t) {
            Toast.makeText(Usuario_BusquedaActivity.this, "Fallo", Toast.LENGTH_SHORT).show();
        }
    });

}

The problem is that the activity where the method runs gets very slow and takes a long time to even hit a button. This appears in the log:

  

I / Choreographer (1378): Skipped 55 frames! The application may be   doing too much work on its main thread.

Thank you very much.

    
asked by RubenSM 05.05.2017 в 20:44
source

1 answer

3
  

The application may be doing too much work on its main thread

This is not really an error, but it is a warning, as the description indicates, a lot of processing is being done on the main thread.

  

To fix this, it is necessary to identify the points where there is or   possibly a long processing time will occur. The best   way is to do all the processing no matter how small or large   in a thread separated from the main thread of the user interface.   is to access data from a SQLite database or do   some hardcore math operations or just order an array   - Do it in a different Thread.

link

    
answered by 06.05.2017 / 00:13
source