Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we need to call onComplete() of subject in onDestroy() method of activity ? #220

Open
bembem1011 opened this issue Sep 6, 2019 · 2 comments

Comments

@bembem1011
Copy link

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()
}
@AgiMaulana
Copy link

For what? If you haven't supposed to do anything on onComplete on the observer you don't need to do that.

@WendyYanto
Copy link

WendyYanto commented May 11, 2020

onComplete is used to indicate that current streams has finished in emitting the data. When your code has finished emitting all the data needed for the observer, then you should call onComplete for this use case to notify the observer. For me, dispose?.dispose() is enough as it already unsubscribe the subscription to prevent any callback on destroyed activity.

Here's references to help you:

  1. https://blog.mindorks.com/understanding-rxjava-subject-publish-replay-behavior-and-async-subject-224d663d452f
  2. http://reactivex.io/RxJava/javadoc/rx/subjects/PublishSubject.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants