0

If in ActivityA, it keep reference to

private val subjectA: PublishSubject<ObjectB> = PublishSubject.create()
private var dispose: Disposable? = null

Does we need to call onComplete() method of subject in onDestroy() method of Activity

override fun onDestroy() {
    subjectA.onComplete()
    dispose?.dispose()
    super.onDestroy()
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Hien Nguyen
  • 744
  • 2
  • 7
  • 20
  • What exactly you want to achieve? In normal cases, their is no need to call `onComplete()` of `subject` in `onDestroy`. – Prithvi Bhola Sep 06 '19 at 05:45
  • Not required, if you are disposing it. Add subjectA in a CompositeDisposable (you can use same composite-disposable for all your subject in one class). Dispose that in onDestroy – Ankit Dubey Sep 06 '19 at 06:11

1 Answers1

0

There is no need(and you should not call) of calling onComplete in onDestroy of Activity/fragment as it is used to issue the stream that the data transfer is completed and when view is destroyed it is not same as completion.You should just dispose the Disposable as Dispose is a different use-case and stop any further push-based notifications instead of telling the observer onError/onComplete.

From documentation:

Notifies the Observer that the Observable has finished sending push-based notifications.

To understand difference between dispose and complete refer below link's:

Anmol
  • 8,110
  • 9
  • 38
  • 63