Coder Social home page Coder Social logo

Can not subscribe to observable again once the app is unsubscribed with FormValidationCombineLatestFragment about rxjava-android-samples HOT 7 CLOSED

kaushikgopal avatar kaushikgopal commented on May 22, 2024
Can not subscribe to observable again once the app is unsubscribed with FormValidationCombineLatestFragment

from rxjava-android-samples.

Comments (7)

marukami avatar marukami commented on May 22, 2024
  1. The onDestroy is not not guaranteed to be called So I generally put my unsubscribe calls is the onStop. For this example onPause is also fine.
  2. It does recreate the subscription and the observable s. The issues is when you restart the fragment you lose the observable s and the new observable once again will skip the first event. So, you have to enter something in each field again before it will validate the fields.

from rxjava-android-samples.

marukami avatar marukami commented on May 22, 2024

Sorry you are also right in that _combineLatestEvents should be in onStart or onResume.

from rxjava-android-samples.

tomoima525 avatar tomoima525 commented on May 22, 2024

@marukami
Thank you for your reply.

  1. My concern here is that after the validation is passed and the app goes background and comes to foreground, the "Submit" button is kept enabled even if I changed inputs to invalid entries. The screen below shows the issue.

screen shot 2016-02-02 at 18 59 25

The only way to avoid this issue was to call _combineLatestEvents() at onCreateView() and _subscription.unsubscribe() at onDestroy().
Calling _subscription.unsubscribe() at onStop() reproduced the issue as well. I was wondering if there is any other option to solve this.

new observable once again will skip the first event

Oh, I didn't know this function. I got your point. Thank you.

from rxjava-android-samples.

marukami avatar marukami commented on May 22, 2024

Instead of using skip you could use filter and prevent events from empty fields. So, that way when the fragment resumes form a valid state the Func3 is invoked, and editing any field will also invoke the Func3. I've made a fork you can see here CombineLastest with filter.

Only issue with doing it this way is you lose the invalid state when the field is empty. I'll work on dealing with that edge case after work.

from rxjava-android-samples.

marukami avatar marukami commented on May 22, 2024

So I added a skipWhile so it will now handle the empty field after editing use case. @kaushikgopal thoughts/suggestions on if this should be a PR?

from rxjava-android-samples.

tomoima525 avatar tomoima525 commented on May 22, 2024

@marukami great. This is a better solution. I would recommend this as a PR.

from rxjava-android-samples.

kaushikgopal avatar kaushikgopal commented on May 22, 2024

hey @tomoima525 : sorry for keeping this issue alive forever. over the course of the numerous changes, at some point, i changed the unsubscribing to happen onDestroyView. This in concert with onCreateView should do the trick.

if i'm missing something, feel free to chime in.

as always thanks @marukami for the insight on what was happening in the first place.

from rxjava-android-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.