When I debug my app I see that onPostExecute starts after onPreExecute and only when it is finished doInBackground method start running, so I don't have results on UI. Why it could be? AsyncTask code:
class TranslateYandex extends AsyncTask<Void, Void, Void> {
String translate = "";
// YandexTranslation yandexTranslation;
@Override
protected void onPreExecute() {
super.onPreExecute();
enterWord.setEnabled(false);
getTranslateButton.setEnabled(false);
translate = enterWord.getText().toString();
}
@Override
protected Void doInBackground(Void... voids) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://translate.yandex.net")
.addConverterFactory(GsonConverterFactory.create())
.build();
YandexService service = retrofit.create(YandexService.class);
Call<YandexTranslation> call = service.getTranslation(translate, API_KEY, LANG);
call.enqueue(new Callback<YandexTranslation>() {
@Override
public void onResponse(Call<YandexTranslation> call, Response<YandexTranslation> response) {
if (response.body() != null){
Log.i("Response", response.body().getTranslation().get(0));
translation = response.body().getTranslation().get(0);
int donothing = 1;
}
else {
Log.i("Response", " is null");
}
}
@Override
public void onFailure(Call<YandexTranslation> call, Throwable t) {
Log.i("Failure", t.toString());
}
});
return null;
}
protected void onPostExecute(Void voids) {
enterWord.setEnabled(true);
getTranslateButton.setEnabled(true);
enterTranslation.setText(translation);
}
}