Android: green eventbus robot: multiple events received in one message

I use the green robot event bus in Android

I fire all events using EventBus.getDefault (). post and onStop I call EventBus.getDefault (). unregister (this); in my work. However, as soon as I click and reopen the application, several onEvent () are accepted on one event message. Has anyone else encountered this problem?

@Override
protected void onStart() {
    super.onStart();
    getBus().register(this);
}

@Override
protected void onPause() {
    getBus().unregister(this);
    super.onPause();
}

@Override
protected void onStop() {
    getBus().unregister(this);
    super.onStop();
}


protected EventBus getBus() {
    return EventBus.getDefault();
}
+4
source share
1 answer

. , , . , , , . , .

mBus = EventBus.getDefault();

void registerAndCheck(Object helper)
{
    if(!mBus.isRegistered(helper))
    {
        mBus.register(helper);
    }
}


mFileHelper = new FilesHelper();
registerAndCheck(mFileHelper);

, -.

+5

Source: https://habr.com/ru/post/1599623/


All Articles