I'm working on a bluetooth project that uses RxAndroidBle for bluetooth communication. I came across two different ways that the subscriptions are cleaned up. I was wondering if anyone could explain the differences and benefits of each if there are any. The two examples are as follows.
First: using a PublishSubject
to trigger a disconnect with the bluetooth device
Second: disconnecting with the bluetooth device by unsubscribing from the Subscription
My main focus is on the triggerDisconnect()
methods in each of the examples. In what ways is the PublishSubject
way different from just keeping a reference to the Subscription
and then unsubscribing?
I do apologize for how open ended this question is but I'm not sure how better to explain it.
No, PublishSubject disconnectTriggerSubject
help construct connectionObservable
using this prepareConnectionObservable()
method earlier. Then act as a proxy to pass null
to onNext()
method of the observable.
Then inside onNext()
of this subscription:
.subscribe(
characteristic -> {
updateUI(characteristic);
Log.i(getClass().getSimpleName(), "Hey, connection has been established!");
},
this::onConnectionFailure,
this::onConnectionFinished
);
the updateUI(characteristic)
method is get called with null
value.