i'm trying to add a indeterminate progressDialog to my UI once i click a list element that calls a AsyncTask, but unfortunately, if I call the dialog on the onPreExecute like this:
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.setProgressStyle(R.style.AppTheme_Dark_Dialog);
dialog.setIndeterminate(true);
dialog.setMessage(activity.getString(R.string.Buscando));
dialog.show();
}
Obs: Worth noting that the Async is not a subClass of the Activity Class, i'm passing the activity as a parameter to the constructor.
and
@Override
protected void onPostExecute(BuscaPendentesFechamento buscaPendentesFechamento) {
super.onPostExecute(buscaPendentesFechamento);
if(dialog.isShowing())
dialog.dismiss();
}
the dialog simply doesn't show at all, although it is created and called(alredy checked, the activity instance is correct)
and if I set the dialog on the activity itself, like:
final ProgressDialog progressDialog = new ProgressDialog(RegistraPeso.this, R.style.AppTheme_Dark_Dialog);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(getString(R.string.Buscando));
progressDialog.show();
BuscaPendentesFechamento exportProjectRequisition = new BuscaPendentesFechamento(getApplicationContext());
response = exportProjectRequisition.execute(nomeEquip,RegistraPeso.this);
progressDialog.dismiss();
the Dialog shows on the Ui, but only after the AsyncTask alredy performed, and not before it is called, and according to the code, it should be showing before the Async even gets created.
What can I do? What am I doing wrong? Please help.
Edit: Added where the Dialog is created:
private ProgressDialog dialog;
private RegistraPeso activity;
BuscaPendentesFechamento(RegistraPeso activity) {
this.dialog = new ProgressDialog(activity);
this.activity = activity;
}
Edit: Added the doInBackground:
@Override
protected BuscaPendentesFechamento doInBackground(String... params) {
ArrayList<UmData> jsonArrayResponse = JSONParser.makeHttpRequestArray(
Constants.URL_PENDENTES_FECHAMENTO,
Constants.METHOD_POST, requisition.writeJSON(params[0]),
requisition.getContext());
if(jsonArrayResponse!=null)
requisition.setJsonArrayResponse(jsonArrayResponse);
else {
UmData umData = new UmData();
umData.setItemUm("Server not responding");
jsonArrayResponse = new ArrayList<>();
jsonArrayResponse.add(umData);
requisition.setJsonArrayResponse(jsonArrayResponse);
}
return requisition;
}