Git Product home page Git Product logo

Comments (13)

BenSchwab avatar BenSchwab commented on June 17, 2024 1

No, I don't think so, as the subscriptions would be disposed in onDestroyView so they can be safely recreated in onCreateView.

from mavericks.

gpeal avatar gpeal commented on June 17, 2024 1

@BenSchwab Yeah, makes sense. Want to take a stab at it?

from mavericks.

justsosoxd avatar justsosoxd commented on June 17, 2024

Sometimes having all subscriptions in onCreate is really annoying since views have not been created here which means everything used in the callback need to be a member of the fragment instead of a local variable. And it's also error prone cuz this is not guaranteed by any compile-time checking .

Why not try using getViewLifecycleOwner instead of this for a fragment? This only requires upgrading support library version to 28.

from mavericks.

gpeal avatar gpeal commented on June 17, 2024

@justsosoxd That should be okay because the subscription will only get called when the fragment is in the STARTED lifecycle.

from mavericks.

gpeal avatar gpeal commented on June 17, 2024

@BenSchwab What is actionable here?

from mavericks.

ubuntudroid avatar ubuntudroid commented on June 17, 2024

@justsosoxd wouldn't using getViewLifecycleOwner() possibly make things even worse? The view lifecycle can be even shorter in case of detached Fragments than the one of the Fragment itself as per the documentation.

from mavericks.

BenSchwab avatar BenSchwab commented on June 17, 2024

@gpeal We could start logging a warning (or crash) if you subscribe after onCreate? Or maybe we could keep a list of active subscribers references and no-op if one already exists? (I would need to look into how references work on lambdas, not sure if this is possible.)

from mavericks.

justsosoxd avatar justsosoxd commented on June 17, 2024

@ubuntudroid If I get it right, the problem we need to solve here is duplicated subscription when fragments are added to backstack then resumed. view lifecycle can avoid this problem as the subscription will be canceled when fragment is added to backstack. why would it make things worse?

from mavericks.

ubuntudroid avatar ubuntudroid commented on June 17, 2024

@justsosoxd uh, I think I got the problem statement wrong. After rereading I think you are actually right. Sorry for the confusion!

from mavericks.

gpeal avatar gpeal commented on June 17, 2024

@BenSchwab True, we could check lifecycle state and make sure that it equals CREATED.

from mavericks.

gpeal avatar gpeal commented on June 17, 2024

@BenSchwab What do we want to do here?

from mavericks.

BenSchwab avatar BenSchwab commented on June 17, 2024

I think we can change subscriptions made after onCreate to use getViewLifecycleOwner .

Need to add tests, but this is what it would look like: b76d71b

from mavericks.

gpeal avatar gpeal commented on June 17, 2024

@BenSchwab How would using the view lifecycle owner solve this? Wouldn't you still have duplicate subscriptions?

from mavericks.

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.