0

I am using Greenbot EventBus in my app and am getting like a 2 second delay when I press a button that fires an event.

My EventBus class ResetArmyEven.java

public class ResetArmyEvent {
}

it is triggered here:

   public void onClick(View v) {
    ResetArmyEvent resetArmy = new ResetArmyEvent();
    EventBus.getDefault().post(resetArmy);
} 

I am using this in Fragment A to trigger two events, one in Fragment B and the other in Fragment C. This is my onEvent() trigger

  public void onEvent(ResetArmyEvent event) {
    Utilities.resetArmyAmounts(troopAmountArray);
}

This is the method it calls

    public static void resetArmyAmounts(EditText[] amountsArray) {
    for (EditText amount : amountsArray) {
        amount.setText("");
    }
}

I have tried changing what the event is doing (just simply sending a toast) and that did not help. I have also tried changing the way it is fired (firing method in the XML), and that did not help.

The button has a ripple effect, and even that takes like 2 seconds to trigger. When I remove the EventBus events then it fires right away. So it seems like it has something to do with EventBus. Any ideas on how to speed this up? What am I doing wrong? Thanks.

Ephraim Schmitt
  • 227
  • 2
  • 16
  • Have you tested using something that is not updating your UI, such as breakpoints in a debugger, or `Log` statements? `post()` will directly call your `onEvent()` methods, AFAIK, since `onEvent()` is for receipt on the posting thread. – CommonsWare Sep 22 '15 at 15:58
  • Just tried it with only a Log statement, and you are right that it fires right away. I think I may know what the issue it and will report back once I try something – Ephraim Schmitt Sep 22 '15 at 16:18
  • Ok, so originally I was calling a static utils method for all of the fragments, and I thought that was the issue. It was not. Even when calling only one fragment onEvent and having the work done in that fragment it still gives me a delay. Clearly it has something to do with the fact that I am updating something on the UI, but I don't know how to fix this. – Ephraim Schmitt Sep 22 '15 at 16:23

0 Answers0