Skip to content

Instantly share code, notes, and snippets.

@CodeK1988
CodeK1988 / dialogfragment使用记录
Last active February 8, 2020 12:19
dialogfragment使用记录
dialogfragment使用记录
https://gist.github.com/yizuochengchi/2ad1e5e0127a3d42dd7c569da132c292
@CodeK1988
CodeK1988 / IllegalArgumentException: Cannot add the same observer with different lifecycles
Created April 1, 2020 01:24
IllegalArgumentException: Cannot add the same observer with different lifecycles
场景:dialogfragment(tabLayout+viewpager) + 两个Afragment
解决方案一:
class SafeMutableLiveData<T> : MutableLiveData<T>() {
private var weakLifecycleOwner: WeakReference<LifecycleOwner>? = null
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {
weakLifecycleOwner?.get()?.let {
removeObservers(it)