【发布时间】:2018-09-20 04:03:28
【问题描述】:
我正在使用 Retrofit 从 api 接收 json 数据,并且运行良好,但将来我想显示一个进度条。我决定实现 onProgressUpdate 以检查是否调用了此方法,但是在检查 Logcat 选项卡时,它不起作用。也就是说,该方法没有运行。 AsyncTask 类中的所有其他方法都在工作。我为每种方法都有一个 Toast,所有这些都运行。
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();
}
}
【问题讨论】:
-
调用 publishProgress()
标签: java android android-studio android-asynctask