An enhanced Guava-based event bus with emphasis on Android support.

Related tags

EventBus otto
Overview

Otto - An event bus by Square

An enhanced Guava-based event bus with emphasis on Android support.

Otto is an event bus designed to decouple different parts of your application while still allowing them to communicate efficiently.

Forked from Guava, Otto adds unique functionality to an already refined event bus as well as specializing it to the Android platform.

For usage instructions please see the website.

Deprecated!

This project is deprecated in favor of RxJava and RxAndroid. These projects permit the same event-driven programming model as Otto, but they’re more capable and offer better control of threading.

If you’re looking for guidance on migrating from Otto to Rx, this post is a good start.

Download

Downloadable .jars can be found on the GitHub download page.

You can also depend on the .jar through Maven:

<dependency>
  <groupId>com.squareup</groupId>
  <artifactId>otto</artifactId>
  <version>1.3.8</version>
</dependency>

or Gradle:

implementation 'com.squareup:otto:1.3.8'

Snapshots of the development version are available in Sonatype's snapshots repository.

License

Copyright 2012 Square, Inc.
Copyright 2010 Google, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • added support for inheritance

    added support for inheritance

    This is a solution to the limitation that otto only processes methods of the immediate type, disregarding any annotated super methods. This topic has been discussed here.

    This pull request adds an annotation to the public API of otto which allows the user to explicitly declare classes for which otto should check super classes for annotations (producers/subscribers).

    Credits for the original implementation of this pull request go to @deadfalkon.

    opened by SierraGolf 20
  • otto proguard

    otto proguard

    Otto is a very good library. But when I passed Proguard packaged into APK, data thread transmission failure, I have to follow the instructions to -keepclassmembers class * * { @com.squareup.otto.Subscribe public *; @com.squareup.otto.Produce public *; } Otto demo, the project is, click the button no reaction. Look forward to solve as soon as possible.

    opened by 23code 17
  • Introduce code generation via annotation processing.

    Introduce code generation via annotation processing.

    DO NOT MERGE

    This pretty fundamentally changes how the event bus behaves with regard to registration and unregistration.

    There is now a concept of a Finder<T> whose job is to locate the @Subscribe and @Produce-annotated methods on instances of T. The annotation processor generates finders for each type which perform the installation and uninstallation of subscribers and producers onto the bus.

    A Subscriber<T> is an interface which represents something that can accept an event of type T. A Producer<T> is an interface which represents something that can produce a new event of type T. The annotation processor's code for the Finder<T> calls generated Subscriber and Producer classes which call real methods on the finder's T type.

    Since we cannot guarantee the precense of annotation-generated classes at runtime, a reflection implementation is provided as a fallback which behaves exactly as the v1.x Otto Bus does.

    TODO

    • [ ] Evaluate better invalidation for the unregistration inside of a handler case.
    • [ ] Fix unregistration in a handler/producer tests.
    • [ ] Write integration tests using the Dagger framework.

    Probably a lot more...

    opened by JakeWharton 17
  • Problem using it with AndroidAnnotations

    Problem using it with AndroidAnnotations

    I tried using dagger with AndroidAnnotations within activities. The problem is that AndroidAnnotations creates a subclass of my activity. When you look for annotated subscribers in com.squareup.otto.AnnotatedHandlerFinder#loadAnnotatedMethods you use listenerClass.getDeclaredMethods() This does not return the methods from the super-class. So I can not receive messages if I create a subclass of the class that contains subscribe methods. I got around this by registering an anonymous class with an annotated method. Not sure if you want to support this, just mentioned it. Thanks, Gabi

    opened by gdogaru 16
  • Refreshing the screen (fragment) from another thread

    Refreshing the screen (fragment) from another thread

    Hi, I am using Otto on my application. It works well.

    I would be interested in refreshing the screen from an event in an intentservice (which has its own thread).

    For that, I am trying to use Otto with ThreadEnforcer.ANY

    But I got the same exception that I would obtain if I would call the view directly from the intentService (means other that the main thread). Is there a way in Otto to "redirect" easily the event from the IntentService to the Main thread ??? I just want to know when to do it.

    Thank you

    Michael

    opened by pommedeterresautee 16
  • Bug on unregister

    Bug on unregister

    Already registered my activity at onResume() but still running into this exception when I un-register it at onPause(). However, I'd like to suggest better error handling. If the object is really not registered, why don't Bus just ignore it when there is a call to un-register, instead of throwing an exception and crash the app?

    Caused by: java.lang.IllegalArgumentException: Missing event handler for an annotated method. Is class com.company.activity.MyActivity registered? at com.squareup.otto.Bus.unregister(Bus.java:288) at com.company.activity.MyActivity.onPause(SingleTripResultActivity.java:231) at android.app.Activity.performPause(Activity.java:5493) at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1251) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3171) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3140) at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3118) at android.app.ActivityThread.access$1000(ActivityThread.java:157) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5293) at java.lang.reflect.Method.invokeNative(Method.java) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at dalvik.system.NativeStart.main(NativeStart.java)

    opened by tungle 15
  • Iterate over interfaces upon event dispatch

    Iterate over interfaces upon event dispatch

    This should allow for some more interesting event hierarchies.

    Code should compile and run with mvn clean verify, although I was unable to test the otto-sample stuff, because I didn't want to install Maven 3.1.1 (which the android-maven-plugin requires).

    opened by bgw 14
  • Allow to use Otto with AndroidAnnotations' generated classes.

    Allow to use Otto with AndroidAnnotations' generated classes.

    There is a problem using https://github.com/excilys/androidannotations with Otto. When we pass this to Otto, it can see generated by AA class, which doesn't have any @Subscribe and @Produce annotations. The first solution is to wrap all annotated methods on ClassA_ in the AndroidAnnotations project, something like this:

    @EActivity
    class ClassActivity{
      @Subscribe public void onMyEvent(Event event){
        //...
      }
    }
    

    Generated class could be:

    class ClassActivity_{
      @Subscribe public void onMyEvent_(Event event){
        onMyEvent(event);  
      }
    }
    

    We use wrappers for methods to call this.onMyEvent which could be overriden in ClassActivity_

    But it is rather complicated to generate lots of code. The easiest way is to modify Otto a bit. We assume, that ClassA_ is generated by AA from ClassA.

    opened by naixx 14
  • Make static hashmaps thread safe

    Make static hashmaps thread safe

    See issue https://github.com/square/otto/issues/148 .

    This change makes the static producer/subscriber hashmaps thread safe.

    Note, there may be other parts that aren't thread safe but this covers what we've seen to be the most common issue.

    opened by ashoykh 13
  • Registering an parent class does not work

    Registering an parent class does not work

    I have a parent activity that contains a @Subscribe method. When I try to register the parent using bus.register(this), the AnnotatedHandlerFinder finds all @Subscribe methods in the child class, not in the parent.

    That's because: AnnotatedHandlerFinder.findAllSubscribers() take the class of the instance and not the parent.

    A solution would be to add a new method bus.register(this, listenerClass), where listenerClassis the type of the parent object?

    opened by mr-thierry 13
  • How to unregister in plain Java Objects?

    How to unregister in plain Java Objects?

    In the samples I register and unregister on Bus in the onResume() and onPause() callbacks. But how do I use Otto in plain Java Objects? (no Activity, Fragment and so on). In plain Java Objects I can register in the constructor but where I have to unregister?

    opened by screendriver 12
  • java.lang.RuntimeException: Could not dispatch event: class abc to handler

    java.lang.RuntimeException: Could not dispatch event: class abc to handler

    at com.squareup.otto.Bus.throwRuntimeException(Bus.java:460) at com.squareup.otto.Bus.dispatch(Bus.java:387) at com.squareup.otto.Bus.dispatchQueuedEvents(Bus.java:368) at com.squareup.otto.Bus.post(Bus.java:337) at com.squareup.otto.Bus.throwRuntimeException(Bus.java:460) at com.squareup.otto.Bus.dispatch(Bus.java:387) at com.squareup.otto.Bus.dispatchQueuedEvents(Bus.java:368) at com.squareup.otto.Bus.post(Bus.java:337)

    opened by Asad4429 0
  • Private EventHandler makes it impossible to override Bus#dispatch

    Private EventHandler makes it impossible to override Bus#dispatch

    It would be nice if EventHandler was package public, so that subclasses of Bus could override dispatch. I have that change in a local fork, but I'd rather depend on the official library.

    opened by thiagohiraisc 1
  • Using privitives in callback haven't invoked it.

    Using privitives in callback haven't invoked it.

    So I said: bus.post(228); //int

    and then tried to get it inside my Fragment and it haven't worked.

    Then I changed it to String and everything became fine.

    Is it ok?

    opened by lectricas 3
  • Examples

    Examples

    Good morning, it is the first time I will use Otto and I wonder if you could give an example of that class should be created and where it should place the functions, which will be @Subscribes. I understand the operation, but I can not understand where they are to be the functions that are activated by the certain event, which want to capture to make a sincrinización between threads. Thank you and I hope your help.

    PS: if I do not explained well, ask and I write otherwise

    opened by seransaca 1
  • Allow for explicit class targeting when registering producer/subscriber methods

    Allow for explicit class targeting when registering producer/subscriber methods

    When registering/unregistering within parent classes consumers now have the ability to point to the parent and use producer/subscriber annotated methods within. This uses the child class instance to reflectively trigger the parent class method.

    opened by wildsmith 0
Bus Scheduler - The source code for the Bus Scheduler app codelab

Bus Scheduler App This folder contains the source code for the Bus Scheduler app

Dania Puertas 0 Jan 7, 2022
Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.

EventBus EventBus is a publish/subscribe event bus for Android and Java. EventBus... simplifies the communication between components decouples event s

Markus Junginger 24.2k Jan 7, 2023
Event pattern & event properties framework

Renetik Android - Event & Property https://github.com/renetik/renetik-android-event Documentation Framework to enjoy, improve and speed up your applic

Renetik 2 Nov 2, 2022
The source code for the Bus Scheduler app codelab

Bus Scheduler App This folder contains the source code for the Bus Scheduler app codelab. Introduction The Bus Scheduler app displays a list of bus st

null 0 Nov 8, 2021
EventBus for Android,消息总线,基于SharedFlow,具有生命周期感知能力,支持Sticky,支持线程切换,支持延迟发送。

背景 跨页面通信是一个比较常见的场景,通常我们会选择使用EventBus,但EventBus无法感知声明周期,收到消息就会回调,所以有了LiveData之后很快就有了LiveEventBus。不过它也有缺点,比如不能切换线程。

BiuBiuQiu0 167 Jan 3, 2023
A lightweight eventbus library for android, simplifies communication between Activities, Fragments, Threads, Services, etc.

AndroidEventBus This is an EventBus library for Android. It simplifies the communication between Activities, Fragments, Threads, Services, etc. and lo

Mr.Simple 1.6k Nov 30, 2022
Powerful event-bus optimized for high throughput in multi-threaded applications. Features: Sync and Async event publication, weak/strong references, event filtering, annotation driven

MBassador MBassador is a light-weight, high-performance event bus implementing the publish subscribe pattern. It is designed for ease of use and aims

Benjamin Diedrichsen 931 Dec 23, 2022
PubSub - 使用 Kotlin Coroutines 实现的 Local Pub/Sub、Event Bus、Message Bus

PubSub 使用 Kotlin Coroutines 实现的 Local Pub/Sub、Event Bus、Message Bus 下载 将它添加到项目的

Tony Shen 4 May 30, 2022
Bus Scheduler - The source code for the Bus Scheduler app codelab

Bus Scheduler App This folder contains the source code for the Bus Scheduler app

Dania Puertas 0 Jan 7, 2022
FractalUtils - A collection of utility functions and classes, with an emphasis on game related utilities

A collection of utility functions and classes written in Kotlin. There is some emphasis on utilities useful for games (Geometry, Random, Time, Updating, etc).

null 2 Nov 11, 2022
Event bus for Android and Java that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.

EventBus EventBus is a publish/subscribe event bus for Android and Java. EventBus... simplifies the communication between components decouples event s

Markus Junginger 24.2k Jan 7, 2023
Android library listening network connection state and change of the WiFi signal strength with event bus

NetworkEvents Android library listening network connection state and change of the WiFi signal strength with event bus. It works with any implementati

Piotr Wittchen 452 Nov 21, 2022
Event Bus powered by Kotlin Coroutines Flow

FlowBus FlowBus is a kotlin event bus implementation. Powered by Kotlin Coroutines and Flows Android MainThread-aware Fully operable from Java code Ex

Robert Kosakowski 26 Dec 27, 2022
An enhanced version of the Volley Networking Toolkit for Android

enhanced-volley An Enhanced version of the Volley Networking Tookit for Android License Copyright (C) 2011 The Android Open Source Project Copyright (

Vinay Shenoy 150 Nov 15, 2022
Android application allowing to sniff and inject Zigbee, Mosart and Enhanced ShockBurst packets on a Samsung Galaxy S20

This Android application allows to sniff and inject Zigbee, Mosart and Enhanced ShockBurst packets from a Samsung Galaxy S20 smartphone. It interacts with a set of patches installed on the phone Bluetooth controller, allowing to add new capabilities to communicate using the previously mentioned protocols.

Romain Cayre 52 Nov 1, 2022
This prototype app provides a list of events to be held under an organization (school, college, club, etc.) and the users can manually set event reminders at their scheduled time so that they do not miss an event.

E-CELL NITS Sample App This prototype app provides a list of events to be held under E-Cell NIT Silchar (for example, Srijan 2.0) and the users can ma

Ritam Nath 1 Nov 7, 2021
Event pattern & event properties framework

Renetik Android - Event & Property https://github.com/renetik/renetik-android-event Documentation Framework to enjoy, improve and speed up your applic

Renetik 2 Nov 2, 2022
A basic chart written by kotlin. Support animation loading, touch event monitoring and JSON data.

A basic chart written by kotlin. Support animation loading, touch event monitoring and JSON data.

null 2 Dec 21, 2022
Okuki is a simple, hierarchical navigation bus and back stack for Android, with optional Rx bindings, and Toothpick DI integration.

Okuki A simple, hierarchical navigation bus and back stack for Android, with optional Rx bindings, and Toothpick integration for automatic dependency-

Cain Wong 143 Nov 25, 2022
This Android app shows bus connections from Koleje Strahov station to Dejvická station and the other way in the city of Prague

This Android app shows bus connections from Koleje Strahov station to Dejvická station and the other way in the city of Prague. These are important for many students from the Czech Technical University in Prague.

Lašťa Apps 3 Jul 28, 2022