optimize Sword

androidx
Ztiany 5 years ago
parent a5a1333b7d
commit 8cb76f797c
  1. 12
      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.AndroidInjection
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import io.reactivex.Flowable import io.reactivex.Flowable
import io.reactivex.plugins.RxJavaPlugins
import timber.log.Timber
/** /**
* useful tools for android development, just like a sword. * useful tools for android development, just like a sword.
@ -75,6 +77,16 @@ object Sword {
return this return this
} }
/** RxJava2的一个重要的设计理念是不吃掉任何一个异常产生的问题是当RxJava2downStream取消订阅后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 { fun enableAutoInject(): Sword {
val activityLifecycleCallbacks: ActivityLifecycleCallbacks = object : ActivityLifecycleCallbacksAdapter { val activityLifecycleCallbacks: ActivityLifecycleCallbacks = object : ActivityLifecycleCallbacksAdapter {
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) { override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {

Loading…
Cancel
Save