美文网首页
EventBus 报“Subscriber class alre

EventBus 报“Subscriber class alre

作者: 魏成 | 来源:发表于2017-07-14 14:04 被阅读145次

分类:androidandroid异常框架

** (432)
** (0)

这句子的话意思也很容易理解,“接收者类已经被注册为事件类了”。
之前我是这么写: 事件注册是写在onStart()里面的
@Override
protected void onStart()
{
super.onStart();
EventBus.getDefault().register(this);
}

Paste_Image.png

解决方式:

@Override
protected void onStart() {
super.onStart();
if(!EventBus.getDefault().isRegistered(this)){//加上判断
EventBus.getDefault().register(this);
}
}

@Override
protected void onDestroy() {
    if (EventBus.getDefault().isRegistered(this))//加上判断
            EventBus.getDefault().unregister(this);
    super.onDestroy();

相关文章

网友评论

      本文标题:EventBus 报“Subscriber class alre

      本文链接:https://www.haomeiwen.com/subject/pdngzttx.html