我有一个带有实时数据变量的视图模型。
我的活动会观察它以更新 UI。
在调试中,一切运行良好。当我启用 proguard 时,它不再观察 livedata 的变化。
我已检查实时数据是否已正确更新。但是,观察者回调永远不会被调用。
有关如何配置 Proguard 以及可能出现什么问题的任何提示?
我尝试保留我的包的类但没有成功:
-keep class com.example.myapp.** { *; }
这是视图模型:
class SplashViewModelImpl : JapetViewModel(), SplashViewModel {
private val isTimeUp = MutableLiveData<Boolean>()
init {
isTimeUp.value = false
Observable.timer(2000L, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { isTimeUp.postValue(true) }
}
override fun isTimeUp(): LiveData<Boolean> = isTimeUp
}
和活动:
class SplashActivity : MyBaseActivity() {
lateinit var viewModel: SplashViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
viewModel = kodein.with(this).instance()
// Working in debug
// viewModel.isTimeUp().observe(this, Observer(this::transitionIfTimeUp))
// Working in debug too, tried this way of writing it too
viewModel.isTimeUp().observe(this, Observer<Boolean> { t -> transitionIfTimeUp(t) })
// Also tried doing it with an object : Observer... without success either
}
private fun transitionIfTimeUp(isTimeUp: Boolean?) {
if (isTimeUp == null || !isTimeUp) return
startActivity<LoginActivity>()
finish()
}
}
编辑:依赖
testCompile "android.arch.persistence.room:testing:1.0.0-alpha3"
androidTestCompile "android.arch.persistence.room:testing:1.0.0-alpha3"
compile "android.arch.lifecycle:extensions:1.0.0-alpha3"
compile "android.arch.lifecycle:reactivestreams:1.0.0-alpha3"
kapt "android.arch.lifecycle:compiler:1.0.0-alpha3"
compile "android.arch.persistence.room:runtime:1.0.0-alpha3"
compile "android.arch.persistence.room:rxjava2:1.0.0-alpha3"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha3"