Firebase offline no CompletionListener on setValue

I have this code base where I set the value. In offline mode, it is written successfully, but does not call the completion function of the call CompletionListener.onComplete.

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 is never called. But he writes beautifully.

In another case, even after canceling the subscription to onDestroy using CompositeSubscription , the subscriber is called when the value is written to the firebase server, even if the fragment is not running.

Is this the right 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 caller receives the call later.

+5
source share
1 answer

The completion listener for write operations will be called when the record has been committed to the database on Firebase servers. When you are offline, this will not happen.

Unable to unsubscribe from the completion listener. If the listener still exists when the write operation is completed, it will be called.

+3
source

All Articles