天蓬老师2017-04-18 09:20:04
The official DEMO is onResume()
注册和onPause()
anti-registration. However, this mechanism may not be suitable for most demand scenarios.
If you are considering de-registering in onCreate(...)
注册和onDestroy()
, there is a situation you need to pay attention to:
If an Activity creates multiple instances, and the Event from EventBus.post(Event) should only be received by the top-level Activity instance, then this will cause problems.
PHP中文网2017-04-18 09:20:04
Register in OnCreat and check whether you have registered before. Repeated registration will result in an error.
Deregister in Destory. I have unregistered it in onPause, and when the page is not visible, the refresh broadcast or other broadcasts sent out cannot be received. After receiving the instance in the top-level Activity, you can also respond by writing OnEvent directly in the View, so before registering, check whether it has been registered. Just use this inside, not Context.
天蓬老师2017-04-18 09:20:04
Who registers and who logs out? Register and unregister are the most scientific in the same category