Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register in onCreate() can not refresh ui #647

Open
kcjian opened this issue Jul 8, 2020 · 1 comment
Open

Register in onCreate() can not refresh ui #647

kcjian opened this issue Jul 8, 2020 · 1 comment

Comments

@kcjian
Copy link

kcjian commented Jul 8, 2020

I will refresh ui when I received this event that send before entering this activity

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    fun eventLock(operateEvent: OperateEvent) {
        LogUtil.e(TAG, "Locked")
        layoutOnOff.setBackgroundResource(R.drawable.ic_oval_state_locked) 
        tvLockState.setText (R.string.Lock_State_Locked)
    }

if I register in onCreate() , unregister in onDestroy ,when i repeated entry and exit,The UI has not changed,But the log shows that the execution is here LogUtil.e(TAG, "Locked")(It happened after the second entry)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        EventBus.getDefault().register(this)
    }
    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }

if I register in onResume() , unregister in onPause,It is no problem

    override fun onResume() {
        super.onResume()
        EventBus.getDefault().register(this)
    }

    override fun onPause() {
        super.onPause()
        EventBus.getDefault().unregister(this)
    }

Eventbus version is 3.2.0
Look forward to your reply

@kcjian kcjian changed the title Can not refresh ui Register in onCreate() can not refresh ui Jul 8, 2020
@greenrobot-team
Copy link
Collaborator

This is likely due to using threadMode = ThreadMode.MAIN. Either drop that, or alternatively synchronously check for the sticky event, like EventBus.getDefault().getStickyEvent(OperateEvent::class.java).
https://greenrobot.org/eventbus/documentation/configuration/sticky-events/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants