What's the correct way to unsubscribe from Sin

2019-08-26 05:42发布

问题:

This question already has an answer here:

  • The result of subscribe is not used 5 answers

I want to do something after short delay:

public void notifyMe() {
Single
       .timer(500, TimeUnit.MILLISECONDS)
       .subscribeOn(Schedulers.io())
       .subscribe(ignore -> service.notifyMe()));
}

Now I have a warning: "The result of subscribe is not used". How can I fix it?

回答1:

A Single will only call once. Upon calling either method, the Single terminates and the subscription to it ends.

Link can be referred for more information.