public class Messenger
extends java.lang.Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
Messenger.NotMsgType |
| 构造器和说明 |
|---|
Messenger() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Messenger |
getDefault() |
static void |
overrideDefault(Messenger newWeakMessenger) |
void |
register(java.lang.Object recipient,
Action0 action) |
void |
register(java.lang.Object recipient,
boolean receiveDerivedMessagesToo,
Action0 action) |
<T> void |
register(java.lang.Object recipient,
boolean receiveDerivedMessagesToo,
java.lang.Class<T> tClass,
<any> action)
see {}
|
<T> void |
register(java.lang.Object recipient,
java.lang.Class<T> tClass,
<any> action) |
void |
register(java.lang.Object recipient,
java.lang.Object token,
Action0 action) |
<T> void |
register(java.lang.Object recipient,
java.lang.Object token,
boolean receiveDerivedMessagesToo,
<any> action,
java.lang.Class<T> tClass)
see {}
|
void |
register(java.lang.Object recipient,
java.lang.Object token,
boolean receiveDerivedMessagesToo,
Action0 action) |
<T> void |
register(java.lang.Object recipient,
java.lang.Object token,
java.lang.Class<T> tClass,
<any> action)
see {}
|
static void |
reset() |
<T> void |
send(T message)
send the message type of T, all receiver can receive the message
|
<T> void |
send(T message,
java.lang.Object token)
send the message type of T, all receiver can receive the message
|
void |
sendNoMsg(java.lang.Object token) |
void |
sendNoMsgToTarget(java.lang.Object target)
send to recipient directly with has not any message
|
void |
sendNoMsgToTargetWithToken(java.lang.Object token,
java.lang.Object target)
send message to target with token,when a receiver has register with same token,it will
receive this msg
|
<T,R> void |
sendToTarget(T message,
R target)
send message to recipient directly
|
void |
unregister(java.lang.Object recipient)
Unregister the receiver such as:
WeakMessenger.getDefault().unregister(this)" in onDestroy in the Activity is required avoid
to
memory leak!
|
<T> void |
unregister(java.lang.Object recipient,
java.lang.Object token) |
public static Messenger getDefault()
public static void overrideDefault(Messenger newWeakMessenger)
public static void reset()
public void register(java.lang.Object recipient,
Action0 action)
recipient - the receiver,if register in activity the recipient always set "this",
and "WeakMessenger.getDefault().unregister(this)" in onDestroy,if in ViewModel,
you can also register with Activity context and also in onDestroy to unregister.action - do something on message receivedpublic void register(java.lang.Object recipient,
boolean receiveDerivedMessagesToo,
Action0 action)
recipient - the receiver,if register in activity the recipient always set "this",
and "WeakMessenger.getDefault().unregister(this)" in onDestroy,if in ViewModel,
you can also register with Activity context and also in onDestroy to unregister.receiveDerivedMessagesToo - whether Derived class of recipient can receive the messageaction - do something on message receivedpublic void register(java.lang.Object recipient,
java.lang.Object token,
Action0 action)
recipient - the receiver,if register in activity the recipient always set "this",
and "WeakMessenger.getDefault().unregister(this)" in onDestroy,if in ViewModel,
you can also register with Activity context and also in onDestroy to unregister.token - register with a unique token,when a messenger send a msg with same token,it
will
receive this msgaction - do something on message receivedpublic void register(java.lang.Object recipient,
java.lang.Object token,
boolean receiveDerivedMessagesToo,
Action0 action)
recipient - the receiver,if register in activity the recipient always set "this",
and "WeakMessenger.getDefault().unregister(this)" in onDestroy,if in ViewModel,
you can also register with Activity context and also in onDestroy to unregister.token - register with a unique token,when a messenger send a msg with same token,it
will
receive this msgreceiveDerivedMessagesToo - whether Derived class of recipient can receive the messageaction - do something on message receivedpublic <T> void register(java.lang.Object recipient,
java.lang.Class<T> tClass,
<any> action)
T - message data typerecipient - {}tClass - class of Taction - this action has one params that type of tClasspublic <T> void register(java.lang.Object recipient,
boolean receiveDerivedMessagesToo,
java.lang.Class<T> tClass,
<any> action)
T - message data typerecipient - receiver of messagereceiveDerivedMessagesToo - whether derived class of recipient can receive the messagetClass - class of Taction - this action has one params that type of tClasspublic <T> void register(java.lang.Object recipient,
java.lang.Object token,
java.lang.Class<T> tClass,
<any> action)
T - message data typerecipient - receiver of messagetoken - register with a unique token,when a messenger send a msg with same token,it
will
receive this msgtClass - class of T for Action1action - this action has one params that type of tClasspublic <T> void register(java.lang.Object recipient,
java.lang.Object token,
boolean receiveDerivedMessagesToo,
<any> action,
java.lang.Class<T> tClass)
T - message data typerecipient - receiver of messagetoken - register with a unique token,when a messenger send a msg with same token,it
will
receive this msgreceiveDerivedMessagesToo - whether derived class of recipient can receive the messageaction - this action has one params that type of tClasstClass - class of T for Action1public void sendNoMsg(java.lang.Object token)
token - send with a unique token,when a receiver has register with same token,it will
receive this msgpublic void sendNoMsgToTarget(java.lang.Object target)
target - WeakMessenger.getDefault().register(this, ..) in a activity,if target set this
activity
it will receive the messagepublic void sendNoMsgToTargetWithToken(java.lang.Object token,
java.lang.Object target)
token - send with a unique token,when a receiver has register with same token,it will
receive this msgtarget - send to recipient directly with has not any message,
WeakMessenger.getDefault().register(this, ..) in a activity,if target set this activity
it will receive the messagepublic <T> void send(T message)
T - message data typemessage - any object can to be a messagepublic <T> void send(T message,
java.lang.Object token)
T - message data typemessage - any object can to be a messagetoken - send with a unique token,when a receiver has register with same token,it will
receive this messagepublic <T,R> void sendToTarget(T message,
R target)
T - message data typeR - targetmessage - any object can to be a messagetarget - send to recipient directly with has not any message,
WeakMessenger.getDefault().register(this, ..) in a activity,if target set this activity
it will receive the messagepublic void unregister(java.lang.Object recipient)
recipient - receiver of messagepublic <T> void unregister(java.lang.Object recipient,
java.lang.Object token)