1

在哪裏/當我應該添加索引的綠色機器人事件總線庫:事件總線指數

EventBus.builder().addIndex(new MyEventBusIndex()).installDefaultEventBus(); 

描述here?我已將這個onCreate()方法應用於我的啓動器活動,但有時會得到:

Caused by: org.greenrobot.eventbus.h: Default instance already exists. It may be only set once before it's used the first time to ensure consistent behavior. 

我在哪裏錯了?非常感謝。

+0

我不知道,但你可能希望把它在構造函數(不帶任何參數): '公共MainActivity(){EventBus.builder()addIndex(新MyEventBusIndex())installDefaultEventBus(。 ); }' – Chaoz

回答

0

你可以在你Android Application class

文檔

注意,在看到Configure the default EventBus instance做一次:這可以默認EventBus實例 是第一次使用前,只有一次完成。隨後調用installDefaultEventBus() 將引發異常。這確保了您的應用程序的一致行爲。 您的應用程序類是在使用之前配置默認的 EventBus實例的好地方。