在我的安卓应用中我使用
org.greenrobot.eventbus.EventBus;
1.我创建事件:
public class NotLoginEvent {
}
在我的 fragment 中发送这个事件:
EventBus.getDefault().post(new NotLoginEvent());
在 Activity 中我收到了这个事件:
@Subscribe() public void onNotLoginEvent(NotLoginEvent notLoginEvent) { // do something }
不错。它工作正常。
但如您所见,NotLoginEvent
类是空的。那么发空类好不好?也许有另一种解决方案。我不想创建空类来发送消息。
最佳答案
您正在以正确的方式进行操作。
public static class MyEvent { /* Additional fields if needed */ }
这是来自官方文档,所以我认为你做得很好。
关于android - EventBus 发送空类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52161158/