Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Otto integration #272

mandrachek opened this Issue · 9 comments

4 participants


I'm using Otto, the bus library from square. I have a couple of methods annotated with @Subscribe, which is part of Otto.

When I add @Trace, it appears that the @Subscribe annotation isn't carried over, so when I post events those methods listen for, nothing happens. When I remove @Trace, they fire off as expected.

public class LoginActivity extends Activity {
    protected EditText username;

    protected EditText password;

    protected Button loginButton;

    @Click({ })
    public void sendLogin() {
        Credentials credentials = new Credentials(
        new LoginTask().run(credentials);

    public void onResume() {

    public void onPause() {

    // @Trace - won't work here (doesn't preserve @Subscribe?)
    public void onLoginFailure(LoginFailureEvent event) {
        Log.w(LoginActivity.class.getName(),"Login Failure");

    // @Trace - won't work here (doesn't preserve @Subscribe?)
    public void onLoginSuccess(LoginSuccessEvent event) {
        Log.w(LoginActivity.class.getName(),"Login Success");


public class LoginTask {    
    public void run(Credentials credentials) {
        // perform login here

    public void post(boolean success) {
        if (success)
            BusProvider.getInstance().post(new LoginSuccessEvent());        
            BusProvider.getInstance().post(new LoginFailureEvent());        

Just FYI, I wound up taking a look at the code generated for the LoginTask_. I ended up dropping the annotations and creating my own version that doesn't hold a reference to the Context (Activity). Might be worthwhile to have @Background(useContext = false) or something.


@mandrachek btw, how did you manage to register your LoginActivity? LoginActivity_ should not have any @Subscribe annotations, as I understand


You can check square/otto#15
It is easier in Otto to fix this


I switched to EventBus, which supposedly has better performance, since it doesn't rely on annotations. I forgot to add a call to register in onCreate, which may have been a problem too.


Just wondering.. do you guys think it'd be interesting to reproduce Otto features in AndroidAnnotations ? Either write an integration layer, or reproduce the features with compile time generation of the features (no class parsing) ?

Thinking about a compile time bus event, here are the features I'd see :

@Subscribe and @Produces usage would lead to automatic registration of associated instances. This means, however, that lifecycle must be handled careful (ie register in onResume() and unregister in onPause()).

Then you need to be able to inject a bus instance. Whether there should be only one bus instance, or multiple onces with identifiers, is also a good question.


I know it's an old entry but I'd love this to be integrated to Android Annotations.

@pyricau pyricau was assigned

Me too :)


I think we shouldn't reimplement this, but just use Otto, which works fine.

A future version of Otto is supposed to work with annotation processing. But it's not there yet, and I don't know if it will come for sure.

In the meantime, the only thing we need to do is to override the annotated methods in the generated subclass and delegate the calls to super.

Note: I updated the title of this issue

@pyricau pyricau referenced this issue from a commit
@pyricau pyricau Otto integration: @Subscribe & @Produce methods are overriden to enab…
…le scanning of the subclass #272
@pyricau pyricau referenced this issue

Otto integration #526

@pyricau pyricau closed this in 2aa295e

Interesting! Now I'm using EventBus but I could switch to Otto as it's coming with aa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.