1

Need help with https://github.com/square/otto.

In my application I have

ActivityBase with :

 @Override
protected void onResume() {
    super.onResume();
    SmartApplication.bus.register(this);
}

@Override
protected void onPause() {
    super.onResume();
    SmartApplication.bus.unregister(this);
}

ActivityOperationBase extends ActivityBase with :

@Subscribe
public void onNextStepRequest(NextStepRequestEvent event) {
    //...
}

ActivityMobile extends ActivityOperationBase with FragmentCommonEnterMoney in it. This fragment has button which does

SmartApplication.bus.post(new NextStepRequestEvent(/*params*/));

on it's click. But it doesn't fire

 @Subscribe
 public void onNextStepRequest(NextStepRequestEvent event) {
     //...
 }

What am I doing wrong ?

Dadroid
  • 1,444
  • 15
  • 16

1 Answers1

1

It is because you are creating new NextStepRequestEvent, and not calling onNextStepRequest.

Actually you want to use onNextStepRequest from fragment, to do this create interface

public interface OnNextStepRequestCallback{
  public void onNextStepCallback(NextStepRequestEvent event);
}

and use it

public class ActivityMobile extends ActivityOperationBase implement OnNextStepRequestCallback {

    public void onNextStepCallback(NextStepRequestEvent event){
       onNextStepRequest(event);
    }   
}

To call above method pass OnNextStepRequestCallback's reference to FragmentCommonEnterMoney from ActivityMobile like (or override Fragment's onAttach)

FragmentCommonEnterMoney  frag = new FragmentCommonEnterMoney();
frag.setOnNextStepRequestCallback(this);

inside your FragmentCommonEnterMoney use

public class FragmentCommonEnterMoney  extends Fragment{
private OnNextStepRequestCallback eventCallback;

    public void setOnNextStepRequestCallback(OnNextStepRequestCallback callback) {
         eventCallback = callback;
    }
}

and use eventCallback to trigger onNextStepRequest from your fragment

Haris Qurashi
  • 2,104
  • 1
  • 13
  • 28