Progressdialog stuck using couchbase
I am using replication service from couchbase in one of my projects. I would like to show the progress of replication using Progressdialog with percentage. Since the documentation says I am doing this in AsyncTask
, so
@Override
protected Void doInBackground(Void... params) {
//other code
double total = push.getCompletedChangesCount() + pull.getCompletedChangesCount();
progressDialog.setMax(total);
progressDialog.setProgress(push.getChangesCount() + pull.getChangesCount());
//.....end }
In the cat log I get
I / LoginActivity: Replication progress = 51029 <- this is the number of changes
I / LoginActivity: total replication amount = 56117 <- this number changes as a
The problem is the progressdialog is stuck at 0%, no progress is showing.
Any idea on how I can solve it?
source to share
doInBackground
runs only once, so you can't get updates in your dialog.
Use the AsyncTask method instead onProgressUpdate
:
@Override
protected void onProgressUpdate(Void... params) {
super.onProgressUpdate(values);
double total = push.getCompletedChangesCount() + pull.getCompletedChangesCount();
progressDialog.setMax(total);
progressDialog.setProgress(push.getChangesCount() + pull.getChangesCount());
}
source to share