public class TinyBus extends java.lang.Object implements Bus
from(Context) method.
When you use constructor you create a stand alone bus instance
which is not bound to any context. You are not able to wire(Wireable)
any Wireable's to such bus.
Create your bus using from(Context) method, if you want to use
Wireable's.
| Modifier and Type | Class and Description |
|---|---|
static class |
TinyBus.Wireable
You can wire instances of this class to a bus instance using
wire(Wireable) method. |
| Constructor and Description |
|---|
TinyBus() |
TinyBus(android.content.Context context) |
| Modifier and Type | Method and Description |
|---|---|
void |
cancelDelayed(java.lang.Class<?> eventClass)
Removes a pending event of given type from delivery queue.
|
static TinyBus |
from(android.content.Context context)
Use this method to get a bus instance bound to the given context.
|
TinyBusDepot.LifecycleCallbacks |
getLifecycleCallbacks() |
boolean |
hasRegistered(java.lang.Object obj)
Checks whether given object is currently registered in the bus.
|
boolean |
hasWireable(java.lang.Class<? extends TinyBus.Wireable> wireClass) |
void |
post(java.lang.Object event)
Posts an event to all registered handlers.
|
void |
postDelayed(java.lang.Object event,
long delayMillis)
Causes the event to be posted to the bus after the specified amount of time elapses.
|
void |
register(java.lang.Object obj)
Registers all handler methods on
object to receive events and producer methods to provide events. |
void |
unregister(java.lang.Object obj)
Unregisters all producer and handler methods on a registered
object. |
<T extends TinyBus.Wireable> |
unwire(java.lang.Class<T> wireClass) |
TinyBus |
wire(TinyBus.Wireable wireable) |
public static TinyBus from(android.content.Context context)
Bus instance can be bound to a context.
If you need a singleton instance existing only once for the
whole application, provide application context here. This option
can be chosen for Activity to Service
communication.
If you need a bus instance per Activity, you have
to provide activity context in there. This option is perfect for
Activity to Fragment or
Fragment to Fragment communication.
Bus instance gets destroyed when your context is destroyed.
context - context to which this instance of bus has to be boundpublic void register(java.lang.Object obj)
Busobject to receive events and producer methods to provide events.
If any subscribers are registering for types which already have a producer they will be called immediately with the result of calling that producer.
If any producers are registering for types which already have subscribers, each subscriber will be called with the value from the result of calling the producer.
public void unregister(java.lang.Object obj)
Busobject.unregister in interface Busobj - object whose producer and handler methods should be unregistered.public boolean hasRegistered(java.lang.Object obj)
BusIn most cases, when you (un)register objects inside standard
onStart() and onStop() lifecycle callbacks,
you don't need this method at all. But in some more trickier
cases, when you (un)register objects depending on some other
conditions, this method can be very helpful.
hasRegistered in interface Busobj - the object to checktrue if object is registered or
false otherwisepublic void post(java.lang.Object event)
Buspublic void postDelayed(java.lang.Object event,
long delayMillis)
Bus
Note that the time-base is SystemClock.uptimeMillis(). This means
the time spent in deep sleep will add an additional delay to execution.
postDelayed in interface Busevent - event to be posteddelayMillis - delay (in milliseconds) until the event will be executedpublic void cancelDelayed(java.lang.Class<?> eventClass)
BuscancelDelayed in interface BuseventClass - event type of event to be cancelledpublic TinyBus wire(TinyBus.Wireable wireable)
public <T extends TinyBus.Wireable> T unwire(java.lang.Class<T> wireClass)
public boolean hasWireable(java.lang.Class<? extends TinyBus.Wireable> wireClass)
public TinyBusDepot.LifecycleCallbacks getLifecycleCallbacks()