Which Activity lifecycle methods are best to register/unregister to event bus?

后端 未结 4 1273
迷失自我
迷失自我 2021-02-07 00:00

What is the best place to register and unregister to an event bus (like otto, EventBus, or tinybus) in an Activity and why?

  1. onCre
4条回答
  •  一生所求
    2021-02-07 00:16

    I removed my comment in the above answer that it would be best to register / unregister in onresume/onpause. I got a strange usecase where some if my events werent reaching the annotated subscriber. Seems the best way is to use the onstart / onstop. Here is a good SO post explaining why:

    https://stackoverflow.com/a/19737191/2361947

提交回复
热议问题