in android ,if I use takeUntil for any network and on activity destroy, I use PublishSubject.onNext(null), the relation is gone; if I use CompositeSubscription.add() for any network and on activity destroy, I use CompositeSubscription.unsubscribe(), the relation is gone. what is different ?
I'm sorry, I can't understand what you are asking. Could you post some example code?
You will have better luck with this type of questions on stackoverflow, the editing system there allows other people to help out with the actual question.
Just use the rxjava tag.
@akarnokd
I'm sorry about my english, and I give some code in android.
PublishSubject<Void> detachSignal = PublishSubject.create();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Observable<Object> observable = Observable.create(new Observable.OnSubscribe<Object>() {
@Override
public void call(Subscriber<? super Object> subscriber) {
System.out.print("this is a network");
}
});
observable.takeUntil(detachSignal)
.subscribe(new Action1<Object>() {
@Override
public void call(Object o) {
}
});
}
@Override
public void onDestroy() {
super.onDestroy();
detachSignal.onNext(null);
}
private CompositeSubscription mSubscription;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSubscription.add(Observable.create(new Observable.OnSubscribe<Object>() {
@Override
public void call(Subscriber<? super Object> subscriber) {
System.out.print("this is a network");
}
}).subscribe(new Action1<Object>() {
@Override
public void call(Object o) {
}
}));
}
@Override
public void onDestroy() {
super.onDestroy();
mSubscription.unsubscribe();
}
what is different for destroy the relation between Observer and the Observered
@alexandru-calinoiu
thank you for you notice
They should be functionally identical if there is only a single consumer.
@akarnokd thank you for your answer and if there are several consumer , have any different?
The detach is shared between all of them so if you signal with it, all the other consumers and any future consumers will be completed.
@akarnokd thank you so much, I got it.
I'm closing this issue due to inactivity. If you have further input on the issue, don't hesitate to reopen this issue or post a new one.
Most helpful comment
The
detachis shared between all of them so if you signal with it, all the other consumers and any future consumers will be completed.