I am trying to create a firestore database on Android.
This is my code that inserts the document:
public Observable<Post> createPost(final Post post){
return Observable.create(new Observable.OnSubscribe<Post>() {
@Override
public void call(final Subscriber<? super Post> subscriber) {
try{
DocumentReference documentReference = getCollection().document();
post.setId(documentReference.getId());
documentReference.set(post).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
subscriber.onNext(post);
subscriber.onCompleted();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
subscriber.onError(e);
subscriber.onCompleted();
}
});
}catch (Exception ex){
subscriber.onError(ex);
Log.e(LOG_TAG, ex.getMessage(), ex);
}
}
});
}
The document is inserted into the database, but none of the onSuccess calls and onFailure callbacks run.
Update 1
1) The problem is incompatible, sometimes it works, sometimes callbacks are called after a few hours, sometimes after 3 hours, etc.
2) This happens when there is no internet connection.
Update 2
1) The problem has been reported here and closed. I am not sure how to guarantee the correctness of the data created offline.
source
share