-
Notifications
You must be signed in to change notification settings - Fork 65
EventTask
Carlyle-Lee edited this page Jun 7, 2020
·
4 revisions
public EventTask registerEvents(int ... ids)
Register to watch some global events. Event ids should be unique in current process.
注册监听全局事件。 事件id 需要再当前进程中唯一。
public EventTask registerGroupedEvents(Object obj, int ... ids)
Register to watch some self-defined events. Object is used as a identifier of a event group. Ids can be any integer you want.
注册监听自定义的任务。此时id 可以是自定义的任意整数。
public void unregister()
Unregister to watch events.
取消事件监听。 需要主动unregister或者通过bindActivity 自动unregister,否则可能发生内存泄漏。
🌜 public void bind(Context context)
Bind event task to Activity context , all events will be unregistered when activity is destroyed.
绑定EventTask 到Activity 生命周期。当Activity 销毁后,所有事件将被取消注册。
暂不支持绑定到Fragment
Demo 1:
new EventTask(){
@Override
public void onEvent(int eventId) {
if(eventId == 10){
DebugLog.d("AAASSSS", "called " + 2);
}
}
}.
registerGroupedEvents(groupTargetObject, 1,10,3,4) //注册一些需要被监听的事件、并设置事件所属于的任务组;
.postAsync();
//事件触发代码
TM.triggerEvent(groupTargetObject,10, null);
Demo 2:
new EventTask(){
@Override
public void onEvent(int eventId) {
DebugLog.d("AAASSSS", "called " + 6);
}
}.
registerEvents(R.id.lens_onclick_event)
.postAsync();
TM.triggerEventTaskFinished(R.id.lens_onclick_event);