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

Usage of RxView.clicks() #282

Closed
josh-burton opened this issue Aug 30, 2016 · 4 comments
Closed

Usage of RxView.clicks() #282

josh-burton opened this issue Aug 30, 2016 · 4 comments

Comments

@josh-burton
Copy link

josh-burton commented Aug 30, 2016

Hi,

I wanted to get some clarity on the usage of RxView.clicks(), and whether it's necessary to unsubscribe.

I've seen multiple usages of RxView.clicks():

plain:

 RxView.clicks(view)
                    .subscribe(click -> {});

takeUntil:

 RxView.clicks(view)
                    .takeUntil(RxView.detaches(view))
                    .subscribe(click -> {});

subscription:

Subscription subscription = RxView.clicks(view)
                    .subscribe(click -> {});
//unsubscribe somewhere
subscription.unsubscribe();

Do we need to unsubscribe?

My particular use case is for a child view in a RecyclerView viewholder. Using RxView.detaches() doesn't fit well, because I don't have a clean way to re bind when the view is attached again.

What are your thoughts?

@JakeWharton
Copy link
Owner

Treat a subscribed RxView.clicks() (or any Observable from this library for that matter) like you would the View reference itself. If you pass it (or subscribe to it) somewhere outside the lifetime of the View, you've just leaked your entire activity.

So if you're just subscribing inside your ViewHolder there's no need to unsubscribe just like there'd be no need to unregister a click listener were you doing it manually.

@josh-burton
Copy link
Author

Thanks Jake!

@nidhi-hearsay
Copy link

nidhi-hearsay commented Sep 28, 2018

Is this still valid? Started seeing The result of the subscribe is not used warnings after moving to AndroidX, Kotlin 1.2.71 on RxView.clicks() events inside activity onCreate(). How are you guys handling that?

@lewisevans
Copy link

It's just a warning and @SuppressLint("CheckResult") will stop these showing

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

4 participants