android otto框架讲解

2017-05-03  本文已影响0人  gc_jp

Bus 建议使用单例模式,这里我不做详细说明

if(bus==null){

bus=newBus(ThreadEnforcer.MAIN);

}

1,编写一个对象

public classGetValue {

Stringvalue;

publicGetValue(String value) {

this.value= value;

}

publicString getValue() {

returnvalue;

}

public voidsetValue(String value) {

this.value= value;

}

}


2,在APPlication中注册bus

bus.register(this);


3,编写订阅者,这里可以编写多个订阅者

@Subscribe

public voidGetsdg(GetValue getValue){

mytv.setText(getValue.getValue());

}


。。。。。。。。

4,执行

bus.post(newGetValue("我晒"));

非常简单,强大

上一篇 下一篇

猜你喜欢

热点阅读