I have this codebase where I set a value. In offline mode it writes successfully but is not calling the CompletionListener.onComplete callback function.
newOrderRef.setValue(order, (firebaseError, firebase) -> {
if (firebaseError != null) {
Timber.e(firebaseError.toException(), "Order create failed, id: %s", order.getOrderId());
subscriber.onError(firebaseError.toException());
} else {
Timber.i("Order created, id: %s", order.getOrderId());
newOrderRef.setPriority(0 - timestamp);
subscriber.onNext(firebase.getKey());
subscriber.onCompleted();
}
});
The callback never gets called. But writes fine.
In another case even after unsubscribing in onDestroy
using CompositeSubscription
, the subscriber gets called when the value gets to write to firebase server even when the fragment is not running.
Is this the correct behavior ?
Subscription orderSubscription = OrderManager.createOrder(order)
.subscribe(s -> {
fabShowSuccess();
showSnackbar("onnext Order created " + order.getOrderId());
}, throwable -> {
showSnackbar("Order failed. Make sure your are connected to internet.");
fabShowFailed();
}, () -> {
fabShowSuccess();
showSnackbar("Order created " + order.getOrderId());
});
mCompositeSubscription.add(orderSubscription);
In onDestroy()
I call mCompositeSubscription.unsubscribe();
, but the subscriber gets called later.
The Firebase Realtime Database stores data returned from a query for use when offline. For queries constructed while offline, the Firebase Realtime Database continues to work for previously loaded data. If the requested data hasn't loaded, the Firebase Realtime Database loads data from the local cache.
The Firebase Realtime Database is a cloud-hosted NoSQL database that lets you store and sync data between your users in realtime.
The completion listener for write operations will be invoked when the write has been committed to the database on the Firebase servers. When you're offline, that won't happen.
There is no way to unsubscribe a completion listener. If the listener still exists when the write operation completes, it will be invoked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With