Reputation: 799
I'm receiving json data from an api using Retrofit, and works perfectly, but in the future I want to show a progress bar. I decided to implement the onProgressUpdate in order to check if this method is invoked, but when checking the Logcat tab, it's not working. That is, the method is not running. All other methods inside the AsyncTask class are working. I have a Toast for each method and all of these run.
public class MindicadorTask extends AsyncTask<Void, Void, Void> {
private String TAG = MindicadorTask.class.getSimpleName();
@Override
protected void onPreExecute() {
super.onPreExecute();
Toast.makeText(MainActivity.this, "JSON Downloading", Toast.LENGTH_SHORT).show();
}
@Override
protected Void doInBackground(Void... voids) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(IMindicador.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
IMindicador iMindicador = retrofit.create(IMindicador.class);
Call<Mindicador> call = iMindicador.getAPI();
mMindicador = new Mindicador();
try {
mMindicador = call.execute().body();
} catch (IOException e) {
Log.e(TAG, "" + e.getMessage());
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
Log.e(TAG, "onProgressUpdate was called");
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Toast.makeText(MainActivity.this, "JSON Call was sucessfull", Toast.LENGTH_SHORT).show();
}
}
Upvotes: 0
Views: 77
Reputation: 89
Specify the type data which you want to send to onProgressUpdate method.also call publishProgress method inside doInBackground method which trigers onProgressUpdate method call.
Upvotes: 2
Reputation: 634
You have to pass it some value, instead of Void. Try using an int, for example. As the int iterates, it calls onProgressUpdate().
Upvotes: 2