From 8cb76f797ce7c025ff04938c27ec22b67f3aab7f Mon Sep 17 00:00:00 2001 From: Ztiany Date: Fri, 8 Nov 2019 15:51:43 +0800 Subject: [PATCH] optimize Sword --- lib_base/src/main/java/com/android/base/app/Sword.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib_base/src/main/java/com/android/base/app/Sword.kt b/lib_base/src/main/java/com/android/base/app/Sword.kt index 4a6bed6..9b12a8e 100644 --- a/lib_base/src/main/java/com/android/base/app/Sword.kt +++ b/lib_base/src/main/java/com/android/base/app/Sword.kt @@ -23,6 +23,8 @@ import com.blankj.utilcode.util.AppUtils import dagger.android.AndroidInjection import dagger.android.support.AndroidSupportInjection import io.reactivex.Flowable +import io.reactivex.plugins.RxJavaPlugins +import timber.log.Timber /** * useful tools for android development, just like a sword. @@ -75,6 +77,16 @@ object Sword { return this } + /** RxJava2的一个重要的设计理念是:不吃掉任何一个异常。产生的问题是,当RxJava2“downStream”取消订阅后,“upStream”仍有可能抛出异常,这时由于已经取消订阅, + * “downStream”无法处理异常,此时的异常无人处理,便会导致程序崩溃,解决方案:在Application设置RxJavaPlugin的ErrorHandler。 + * refer: [RxJava2使用过程中遇到的坑](https://github.com/qqiabc521/blog/issues/3) */ + fun setupRxJavaErrorHandler(): Sword { + RxJavaPlugins.setErrorHandler { + Timber.d("RxJavaPlugins error handler receives error: $it") + } + return this + } + fun enableAutoInject(): Sword { val activityLifecycleCallbacks: ActivityLifecycleCallbacks = object : ActivityLifecycleCallbacksAdapter { override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {