Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

}
like image 662
Kurru Avatar asked Feb 21 '23 20:02

Kurru


1 Answers

Subscribe functions need to be public to work. Oops

@Subscribe
public void testEvent(Object bla) {
    Log.d("EventBus Event", bla.toString());
}
like image 76
Kurru Avatar answered Mar 05 '23 04:03

Kurru