如RxBus,一般你只需要订阅如下代码:
task = rxBus.toObserverable(DataBean.class) .subscribe(card -> { //主线程操作 if(cardNo != null){ cardNo.setText(getString(R.string.pcard_no, card.getCardNum())); } });以上我们一般在Activity中启动时订阅,调用网络访问后,根据RxBus注册事件类型返回到Activity中更新UI;但是必须在Activity的onDestroy时切掉task,会产生内存泄漏,下次重新打开并且也会造成异常
io.reactivex.exceptions.OnErrorNotImplementedException: Fragment HashPCardFragment{b1ee517} not attached to a context.