Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Otto event no firing

Tags:

android

otto

I have an activity and it launches a DialogFragment, on completion of an event the DialogFragment posts an event on the Otto Event Bus, this is to fire a method in it's parent activity. I've posted the related code here, the same code is working else where in my app, but here the event is just no firing.

Code in the activity...

 @Subscribe
public void OttoUpdateUI(BudgetUpdateObject budgetUpdateObject)
{
    updateUI();
    Log.d("budget", "Otto updateUI called");
}

@Override
public void onResume() {
    super.onResume();
    BusStand.getInstance().register(BudgetActivityNew.class);
}

@Override
public void onPause() {
    super.onPause();
    BusStand.getInstance().unregister(BudgetActivityNew.class);
}

BusStand class....

public final class BusStand {
private static final Bus BUS = new Bus();

public static Bus getInstance() {
    return BUS;
}

private void BusProvider() {

    }
}

and the firing event...

BusStand.getInstance().post(new BudgetUpdateObject());

I've checked the import in the activity, and I'm not using dagger module, and i'm not using any other event bus. Any help will be much appreciated.

This is the way I launch the DialogFragment from the activity....

AddBudgetDialogFragment addBudgetDialogFragment = new AddBudgetDialogFragment();
addBudgetDialogFragment.setStyle(DialogFragment.STYLE_NO_TITLE,0);
addBudgetDialogFragment.show(getSupportFragmentManager(),"DialogFragment");
like image 962
Giridhar Karnik Avatar asked Aug 23 '15 09:08

Giridhar Karnik


2 Answers

The issue is that you are not registering the Activity Instance, you are registering the class:

BusStand.getInstance().register(BudgetActivityNew.class);

You should change the code to:

BusStand.getInstance().register(this);

That should do it. :)

like image 152
InvertedNetwork Avatar answered Sep 21 '22 20:09

InvertedNetwork


In my case I imported a wrong library class in my class. Check your imports~

For me, replacing:

import com.google.common.eventbus.Subscribe;

with this:

import com.squareup.otto.Subscribe;

Hope this helps someone.

like image 21
Jiyeh Avatar answered Sep 20 '22 20:09

Jiyeh