I wanted a progress dialog to appear while my activity gets some data. I used Async task but however it doesn't show up I have tried all the answers of the previous Stack Overflow questions but none of them seem to work for me
private class BackgroundSync extends AsyncTask<Void,Void,Void> {
ProgressDialog progress = new ProgressDialog(MainActivity.this);
@Override
protected void onPreExecute() {
progress.setMessage("Loading");
progress.setTitle("Loading");
progress.show();
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
/get data
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
progress.dismiss();
super.onPostExecute();
}
}
I have also tried this using
progress = ProgressDialog.show(MainActivity.this,"Loading","Loading");
as one stack overflow answer suggested but it still doesn't show
I also used the below code, but this time the ProgressDialog
doesn't disappear
private class BackgroundSync extends AsyncTask<Void,Void,Void> {
ProgressDialog progress
@Override
protected void onPreExecute() {
progress = new ProgressDialog(MainActivity.this);
progress.show(MainActivity.this,"Loading","Loading");
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
SyncEvents();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
progress.dismiss();
}
}`
What do I do? This ProgressDialog
issue has been taking more than 2 hours to solve