Git Product home page Git Product logo

Comments (4)

JakeWharton avatar JakeWharton commented on July 30, 2024

We debated this early on and opted not to add it at the time. What we found was that in all of the cases where we thought this would be necessary we had either overlooked an unregistration point or had a bug in our code. For example, fragments and activities have onResume/onPause and views have onAttachedToWindow/onDetachedToWindow.

Do you have a specific use case where you are seeing this not be enough?

from otto.

jjNford avatar jjNford commented on July 30, 2024

That makes sense in terms of playing nice and registering/unregistering.

I'm wanting to incorporate Otto in objects running tasks on other threads (like data models). This allows android to handle on configuration changes and gives me the ability to use a producer to get the last model results if they happened to be returned on the screen rotation.

Looking ahead though I feel this won't work great because the models/objects will have to be unregistered on the subscriber callback. This was just an idea, not a must...

Would love to hear your thoughts on this.

from otto.

JakeWharton avatar JakeWharton commented on July 30, 2024

Hey @jjNford,

Not sure if you saw that we just merged #12 which allows for @Produce methods to return null. This means that whenever you have any long-lived classes which manage some state (e.g., last known location) they don't have to worry about registering and unregistering.

With this change a class should register immediately. When the @Produce method is called you can return null to indicate that you don't yet have anything to say. In keeping with the example, once a location is known you would post that event onto the event bus and cache the location (for any further calls to the producer method).

In regard to your follow-up question, we use another Square library called Retrofit which always gives us callbacks on the main thread to eliminate the possibility of race conditions. Since we have this behavior we always know that any posts that occur as the result of a network callback will always be on the correct thread. If you receive your callbacks on a background thread I suggest that you post a runnable to the main thread which takes the action of posting the event to the bus.

from otto.

jjNford avatar jjNford commented on July 30, 2024

No worries, I just have a handler in my libraries activity class with a getActivityHandler() call - I just reconnect here, works fine. Right now I'm having more trouble with ABS than anything - currently haven't found a solution. On 2.3.6 & 2.3.7 devices items added to the bar from the onCreateOptionsMenu in a SherlockFragment (used in a SherlockFragmentActivity) cause the application to crash. We could take this conversation off GitHub if you want (jj.n.ford at gmail.com).

from otto.

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.