Android 番石榴事件总线不工作
我试图在Android中使用Guava eventbus,但我订阅的事件似乎不起作用。。。我做错了什么 这是我的活动:Android 番石榴事件总线不工作,android,guava,event-bus,Android,Guava,Event Bus,我试图在Android中使用Guava eventbus,但我订阅的事件似乎不起作用。。。我做错了什么 这是我的活动: 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.L
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中使用这个时要小心,因为事件是在发布它的线程上传递的,更像是UI线程。