luigi-agosti / seba

Simple event bus for android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SEBA

Seba is a simple event bus for android. It doesn’t use reflection.

You may want to have a look at similar but more recognized libraries implementing the event bus model : otto and eventBus

If you still like to use this library, here is a quick guide. You can always contact me if you want to know more.

How to use it

Typical scenario for this library is the case where from an intent service you need to notify an activity or a fragment.

EventBus instance

Instantiate and share an event bus between event consumers and producers. A good place can be the Application class.


public class MyApplication extends Application {

	private EventBus eventBus;
		
	public void onCreate() {
		eventBus = new EventBus();
	}
		
	public static final EventBus getEventBus() {
		return eventBus;
	}
}

Generator of events.

A generator can be an IntentService. In this case you just need to get a reference from the application class and then send the event.


public class MyIntentService extends IntentService {

	public EventBus eventBus;
		
	public void onCreate() {
		eventBus = Application.getEventBus();
		eventBus.send(new CustomEvent(){});
	}
		
}

CustomEvent need to implement the marker interface Event.


public class CustomEvent implements Event {

}

Consumer of events.

A possible consumer of events is an Activity. The activity need to register and unregister an EventHandler.


private MainThreadEventHandler eventHandler;

public void onResume() {
	eventHandler = new EventHandler.OnMainThread(new Handler()) {
		@Override
		public void handleAnsyc(Event event) {
			//using this type of handler you can do UI changes
		}
	};
	Application.getEventBus().registerHandler(eventHandler, CustomEvent.class);
}

public void onPause() {
	Application.getEventBus().unregisterHandler(eventHandler, CustomEvent.class);
}

Get the jar

Maven

With maven is simple as the project is available on sonatype

<dependency>
  <groupId>com.luigiagosti</groupId>
  <artifactId>seba</artifactId>
  <version>1.0</version>
</dependency>

Download latest

You can download the latest version to your libs folder.

Where it is used

At the moment the library is used on the image search app. Small application to search for images using different apis.
I haven’t see any issue that the app has 300k downloads.

It will nice if you are informing me if you are using the library in your project.

License

Apache License, Version 2.0

About

Simple event bus for android

License:Other


Languages

Language:Java 100.0%