文章 16
浏览 11956
JetPack

JetPack

Lifecycle Lifecycle中Activity和Fragment都已经实现了LifecycleOwner接口,在Presenter层中创建传入owner,也可以传入lifecycle class MyPresenter(owner:LifecycleOwnter){ //在初始化的时候创建Obvserver init{ owner.lifecycle.addObserver(MyViewLifeImpl) } //使用一个内部类单独管理生命周期 private val viewLifeImpl by lazy { ViewLifeImpl() } inner class MyViewLifeImpl:LifecycleEventObserver{ //被动通知View层变化 override fun onStateChanged( source: LifecycleOwner, event: Lifecycle.Event) { when(event){ Lifecycle.Event.ON_START ->{ println("监听开启") } Lifecycle.E....

充实的一天