Otto 事件总线在单个 post 上接收多个事件

Otto event bus receiving multiple events on single post

我正在使用 Otto 和 Dagger。我的一些活动仅在一个 post.

上多次收到

我认为 post 事件:

@Inject Bus mBus;

在构造函数中:

((MyApplication) mContext.getApplicationContext()).inject(this);  

view.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(final View view) {
    Log.d(TAG, "Sending SearchResultClickedEvent.");
    mBus.post(new SearchResultClickedEvent(mModel.getPlaceId()));
  }
});

在超级class为我订阅activity:

@Inject protected Bus mBus;

onCreate()中:

((HarryApplication) getApplicationContext()).inject(this);

在订阅中activity:

@Subscribe
public void on(SearchResultsRecyclerViewHolder.SearchResultClickedEvent event) {
  Log.d(TAG, "SearchResultClickedEvent received.");
}

单击后的日志:

03-26 12:59:51.496  24613-24613/D/SearchResultView﹕ Sending SearchResultClickedEvent.
03-26 12:59:51.496  24613-24613/D/Subscriber﹕SearchResultClickedEvent received.
03-26 12:59:51.497  24613-24613/D/Subscriber﹕SearchResultClickedEvent received.
03-26 12:59:51.499  24613-24613/D/Subscriber﹕SearchResultClickedEvent received.

我没有取消注册我的事件总线对象。

添加了这个并且它按预期工作:

  @Override protected void onPause() {
    super.onPause();
    mBus.unregister(this);
  }