A类中添加
1、定义监听接口
public interface OnPulseHandListener {
void onLeft(boolean isLeft);
}
2、监听调度类
public static class pulseHand{
public static OnPulseHandListener onPulseHandListener = null;
//设置监听器
public void setPulseListener(OnPulseHandListener onPulseHandListener){
this.onPulseHandListener = onPulseHandListener;
}
public static void doPulse(boolean isLeft) {
if (onPulseHandListener != null) {
onPulseHandListener.onLeft(isLeft);
}
}
}
B类中添加
3、期待执行的类中设置监听
public SenderThread.pulseHand pulseHand = new SenderThread.pulseHand();
pulseHand.setPulseListener(new SenderThread.OnPulseHandListener() {
public void onLeft(boolean isLeft) {
Log.i("OnPulseHandListener", "onLeft "+isLeft);
PulseHand(isLeft);
}
});
A类中调用监听执行
4、执行
pulseHand.doPulse(false);