Comments (4)
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.
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.
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.
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)
- duplicate entry: com/squareup/otto/AnnotatedHandlerFinder.class HOT 1
- NoClassDefFoundError when running in Android OS below 5.0. HOT 3
- subcriber received two same event HOT 2
- Please include the deprecated notice in the info website
- Examples HOT 1
- Please add notice to website about otto deprication HOT 1
- How to customize ThreadEnforcer HOT 4
- Using privitives in callback haven't invoked it. HOT 3
- Link for Migrating to RxJava is dead. HOT 1
- Private EventHandler makes it impossible to override Bus#dispatch HOT 1
- OnEvent not calling in navigationdrawer fragment
- otto with JavascriptInterface in api < 17 HOT 1
- Ship proguard rules in the aar? HOT 1
- A new call to post in a subscriber does not call its subscribers until the first call is completed HOT 1
- Reason for its name HOT 1
- android.database.sqlite.SQLiteException: no such table HOT 4
- Update for Gradle 4 and Bus doesnt work more. HOT 3
- I can't receive the event HOT 1
- java.lang.RuntimeException: Could not dispatch event: class abc to handler
- java.lang.RuntimeException: Could not dispatch event HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from otto.