提交 82f127c7 编写于 作者: J JessYan

Add BaseService#useEventBus()

上级 3c4ba09d
......@@ -47,18 +47,33 @@ public abstract class BaseService extends Service {
@Override
public void onCreate() {
super.onCreate();
EventBus.getDefault().register(this);
if (useEventBus())
EventBus.getDefault().register(this);
init();
}
@Override
public void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
if (useEventBus())
EventBus.getDefault().unregister(this);
unDispose();//解除订阅
this.mCompositeDisposable = null;
}
/**
* 是否使用 EventBus
* Arms 核心库现在并不会依赖某个 EventBus, 要想使用 EventBus, 还请在项目中自行依赖对应的 EventBus
* 现在支持两种 EventBus, greenrobot 的 EventBus 和畅销书 《Android源码设计模式解析与实战》的作者 何红辉 所作的 AndroidEventBus
* 确保依赖后, 将此方法返回 true, Arms 会自动检测您依赖的 EventBus, 并自动注册
* 这种做法可以让使用者有自行选择三方库的权利, 并且还可以减轻 Arms 的体积
*
* @return 返回 {@code true} (默认为使用 {@code true}), Arms 会自动注册 EventBus
*/
public boolean useEventBus() {
return true;
}
protected void addDispose(Disposable disposable) {
if (mCompositeDisposable == null) {
mCompositeDisposable = new CompositeDisposable();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册