I’m trying to detect when replication is complete, and if it worked or not. I’ve gone through several iterations of code like:
ReplicatorConfiguration replConfig = new ReplicatorConfiguration(database, uri);
replConfig.setAuthenticator(new SessionAuthenticator(sessionInfo.cookieValue, sessionInfo.cookieDate, sessionInfo.cookieName));
replConfig.setContinuous(false);
replConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PULL);
replicator = new Replicator(replConfig);
replicator.addChangeListener(new ReplicatorChangeListener() {
@Override
public void changed(Replicator replicator, Replicator.Status status, CouchbaseLiteException error) {
Log.d("HS", "status "+status.getActivityLevel()+" prog total "+status.getProgress().getTotal()+" prog comp "+status.getProgress().getCompleted()+" error "+error);
if(error != null) {
if (replicatorListener != null) {
replicatorListener.onFinished(false);
}
}
else if (status.getActivityLevel() == Replicator.ActivityLevel.STOPPED && previousLevel != Replicator.ActivityLevel.STOPPED && database.getCount() > 0) {
if (replicatorListener != null) {
replicatorListener.onFinished(true);
}
}
previousLevel = status.getActivityLevel();
}
});
The problem is that at some point, the status updates stop. I get a status of BUSY with 3/6000 documents completed. Then nothing for 15 minutes. However if I kill the app and restart, it will go to BUSY and then instantly go back to STOPPED state, because it really finished initially within a few seconds.