今天添加一个EventBus的时候,偶然发现@Subscribe标签下的回调执行了多次,但是只post了一次事件,很奇怪,之前使用不会有这个问题!

EventBus多次接收踩坑
post:
EventBus多次接收踩坑
经过打log调试,最终发现是EventBus.getDefault().register(this);注册了多次导致:
EventBus多次接收踩坑
由于业务中BaseFragment会被多次创建,而导致多次执行register,最终将EventBus.getDefault().register(this)及回调移到Activity中,问题解决,故此记录。

另外,post一次,多个地方通过@Subscribe接收回调,能同时在多个地方接收到。

相关文章:

  • 2022-01-09
  • 2021-08-12
  • 2021-11-05
  • 2021-11-17
  • 2021-05-11
  • 2021-05-27
  • 2021-10-13
  • 2021-05-29
猜你喜欢
  • 2022-01-18
  • 2021-09-01
  • 2021-07-08
  • 2021-07-09
  • 2021-07-21
  • 2022-01-15
  • 2021-09-20
相关资源
相似解决方案