0

In my app I use SyncAdapter(AbstractThreadedSyncAdapter) for synchronisation with server. Basically in background service I insert data to sql table, then on finish I want to inform UI to update ListView with new data. For this matter I tried to use GreenRobot EventBus, but no success.

my Event

public class SyncResultMsg {
    public String message="";
    public SyncResultMsg() {}
    public SyncResultMsg(String value) {
        this.message = value;
    }
}

After insert data to database I call EventBus like this

SyncResultMsg event = new SyncResultMsg();
        event.message = "groupsFetched";
        EventBus.getDefault().post(event);

In my Fragment where I show ListView I try to receive EventBus like this:

@Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    @Override
    public void onStop() {
        EventBus.getDefault().unregister(this);
        super.onStop();
    }

public void onEventMainThread(SyncResultMsg event) {
        String msg = event.message;
        if (msg.equals("groupsFetched")){
            showNewData();
        }
    }
Rafael
  • 6,091
  • 5
  • 54
  • 79

1 Answers1

0

Try creating a custom EventBus with your own threadpool. Had a similiar issue and it solved it in my case.

EE66
  • 4,601
  • 1
  • 17
  • 20