我有这个非常直接的宣言
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
EventBus.getDefault().unregister(this);
super.onStop();
}
public void onEventMainThread(RefreshMessage message){
ToastUtils.showLongToast(getActivity(), message.getRefresh() ? "ok":"false");
}
我不知道为什么它还会抛出
没有名为onEvent的公共方法
如果我错过了什么,请告诉我。我的片段也扩展了AbstractClass
答案 0 :(得分:0)
因为我花了这么长时间来调试错误,所以我使用单例实现了我自己的简单EventBus
public class EventBusMainThread {
private static EventBusMainThread selfInstance;
private List<EventBusSubscriber> subscribers;
public EventBusMainThread() {
this.subscribers = new CopyOnWriteArrayList<>();
}
public static EventBusMainThread getInstance(){
if(selfInstance == null)
selfInstance = new EventBusMainThread();
return selfInstance;
}
public synchronized void register(EventBusSubscriber subscriber){
subscribers.add(subscriber);
}
public synchronized void unregister(EventBusSubscriber subscriber){
subscribers.remove(subscriber);
}
public void post(Object message){
for(EventBusSubscriber subscriber : subscribers){
subscriber.onEvent(message);
}
}}