Otto eventBus does not work for me with three fragments

0

I'm using the Otto library as a bus event manager but it does not work well for me. Let's say I have three Fragments let's say FragmentA , FragmentB and FragmentC within the same Activity.

1.-The FragmentB receives an integer of FragmentA . To do this in the FragmentA it does:

   //FRAGMENT_A
   @Override
    public void onCreate() {
      BusProvider.getInstance().register(this);
    }
  @Override
    public void onDestroyView() {
      super.onDestroyView();
      BusProvider.getInstance().unregister(this);
    }

and post a value:

  BusProvider.getInstance().post(5);

Now the FragmentB manages the receipt value

//FRAGMENT_B 
 @Override
    public void onCreate() {
      BusProvider.getInstance().register(this);
    }
  @Override
    public void onDestroyView() {
      super.onDestroyView();
      BusProvider.getInstance().unregister(this);
    }
@Subscribe
public void getNumberB(int num) {
     // pinta el valor
}

Now the FragmentB should send a double to FragmentC ,

//FRAGMENT_B
private void mandarAfragmetC(double numero){
 BusProvider.getInstance().post(numero)
}

Ahrora the FragmentC receives it and paints it:

//FRAGMENT_C 
 @Override
    public void onCreate() {
      BusProvider.getInstance().register(this);
    }
  @Override
    public void onDestroyView() {
      super.onDestroyView();
      BusProvider.getInstance().unregister(this);
    }
@Subscribe
public void getNumberC(double num) {
     // pinta el valor
}

The step of the whole number of A-> B works well, but the step of the value of B-> C does not work, it does not give me any error, the value is never received in @subscribe of FragmentC

this is my Otto class

public class BusProvider{
    private static Bus sBus;
    public static Bus getInstance() {
        if (sBus == null)
            sBus = new Bus();
        return sBus;
    }

Any idea what I'm doing wrong?

    
asked by JoCuTo 12.04.2018 в 21:56
source

1 answer

0

The method Oncreate() of FragmentC must be initialized when you do

private void mandarAfragmetC(double numero){
 BusProvider.getInstance().post(numero)
}

If it is not, the bus event of FragmentB does not find any @Susbcrite when the .post() is generated

    
answered by 19.04.2018 / 09:07
source