Kurru
Kurru

Reputation: 14331

Guava Eventbus not working

I'm trying to use the Guava eventbus in Android but it my subscribed event doesn't seem to work... What am I doing wrong?

This is my activity:

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());
    }

}

Upvotes: 4

Views: 2515

Answers (1)

Kurru
Kurru

Reputation: 14331

Subscribe functions need to be public to work. Oops

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

Upvotes: 8

Related Questions