0

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Yura Shinkarev
  • 5,134
  • 7
  • 34
  • 57
  • Wait, but in my example will be emitted only one value. – Yura Shinkarev Dec 16 '17 at 13:55
  • Is this in an Android application? If so, you should add the result to a `CompositeDisposable`. – akarnokd Dec 16 '17 at 14:17
  • @akarnokd, whats's different between android and java (java test / console application, etc) in this case? And how can help me CompositeDisposable? Anyway somebody should call dispose. So, my question: method scubscribe() return me Disposable, I should call it after I send notify, right? – Yura Shinkarev Dec 16 '17 at 14:40
  • Android has more strict lifecycle and have to be extra careful with leaking flows. On desktop Swing, you should also do `CompositeDisposable.add()` when doing actions in a window that can be closed by the user. You should call `dispose` when the action is no longer needed to happen. If you call it immediately, the notification won't happen. – akarnokd Dec 16 '17 at 15:54
  • Sorry @YuraShinkarev but I thought you were trying to subscribe, not unsubscribe, so my previous comment was not relevant. – GVillani82 Dec 16 '17 at 17:06
  • @akarnokd I wrote `notifyMe` function. I want in background after short delay did some job (service.notifyMe). My public function do not return any variable. I want call and "forgot". So, I want implement with rxjava same: new Thread(new Runnable(){...}).start() or in android: new AsyncTask().execute(). – Yura Shinkarev Dec 16 '17 at 19:33
  • Just suppress that warning. – akarnokd Dec 16 '17 at 20:31

1 Answers1

2

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ankit Kumar
  • 3,663
  • 2
  • 26
  • 38