3

I am using the replication service from couchbase in one of my project. I would like to show the replication progress using a Progressdialog with percentage. As the documentation says I am doing this in an 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 }

On log cat I get

I/LoginActivity: Replication Progress = 51029 <-this number changes
I/LoginActivity: Replication total = 56117 <-this number changes as well

The problem I have is that the progressdialog is stuck in 0%, no progress is showed.
Any idea about how I can solve it?

JoCuTo
  • 2,463
  • 4
  • 28
  • 44

1 Answers1

0

doInBackground is executed only once , so you cannot get any updates on your dialog.

Use AsyncTask's onProgressUpdate method instead:

@Override
protected void onProgressUpdate(Void... params) {
    super.onProgressUpdate(values);
    double total = push.getCompletedChangesCount() + pull.getCompletedChangesCount();
    progressDialog.setMax(total);
    progressDialog.setProgress(push.getChangesCount() + pull.getChangesCount());
}
Hristo Stoyanov
  • 1,960
  • 1
  • 12
  • 24