【问题标题】:Guava Eventbus not working番石榴事件总线不工作
【发布时间】:2012-04-13 04:56:30
【问题描述】:

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

}

【问题讨论】:

    标签: android guava event-bus


    【解决方案1】:

    订阅功能需要公开才能工作。哎呀

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

    【讨论】:

    • 在 Android 上使用它时要小心,因为事件是在发布它的线程上传递的,而更多的是 UI 线程。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多