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?