EvenBus を登録する前に、(必要に応じて) 子クラスでオーバーライドできる基本クラスで保護されたメソッド (または抽象メソッドを持つ抽象クラス) を作成できます。
public class Test extends Fragment{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(doIneedEventBus()){
EventBus.getDefault().register(this);
}
}
@Override
public void onDestroy() {
super.onDestroy();
if(doIneedEventBus()){
EventBus.getDefault().unregister(this);
}
}
protected boolean doIneedEventBus() {
return true;
}
}
子クラス:
public class TestChild extends Test {
@Override
protected boolean doIneedEventBus() {
return false;
}
}
2 番目のオプション:
try {
EventBus.getDefault().register(this);
} catch (Throwable t){
t.printStackTrace();
}
または、この問題がライブラリで修正されるまで待つこともできます -
https://github.com/greenrobot/EventBus/issues/58