android – Guava Eventbus无法正常工作
作者:互联网
我正在尝试在Android中使用Guava事件总线,但我订阅的事件似乎不起作用……我做错了什么?
这是我的活动:
package test.eventbus;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class EventBusTestActivity extends Activity {
EventBus eventbus = new EventBus();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
eventbus.register(this);
eventbus.post("message");
}
@Subscribe
void testEvent(Object bla) {
Log.d("EventBus Event", bla.toString());
}
}
解决方法:
订阅功能需要公开才能工作.哎呀
@Subscribe
public void testEvent(Object bla) {
Log.d("EventBus Event", bla.toString());
}
标签:android,guava,event-bus 来源: https://codeday.me/bug/20190609/1207842.html