番石榴Eventbus不工作

时间:2012-04-13 04:56:30

标签: android guava event-bus

我正在尝试在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());
    }

}

1 个答案:

答案 0 :(得分:8)

订阅功能需要公开才能运作。糟糕

@Subscribe
public void testEvent(Object bla) {
    Log.d("EventBus Event", bla.toString());
}