Lifecycle
Jetpack LifeCycle 库
Lifecycle 解决了什么问题?
internal class MyLocationListener(
private val context: Context,
private val callback: (Location) -> Unit
) {
fun start() {
// connect to system location service
}
fun stop() {
// disconnect from system location service
}
}
class MyActivity : AppCompatActivity() {
private lateinit var myLocationListener: MyLocationListener
override fun onCreate(...) {
myLocationListener = MyLocationListener(this) { location ->
// update UI
}
}
public override fun onStart() {
super.onStart()
myLocationListener.start()
// manage other components that need to respond
// to the activity lifecycle
}
public override fun onStop() {
super.onStop()
myLocationListener.stop()
// manage other components that need to respond
// to the activity lifecycle
}
}代码质量问题
内存泄漏问题
如何使用 LifeCycle
集成 lifecycle 库
创建监听器
未使用Java 8
使用Java8
注册监听器
监听生命周期的源码
处理生命周期事件源码

监听 Activity 生命周期
监听器注解的处理时机
监听应用生命周期
自定义 LifeCyclerOwner
一些小问题
相关链接
最后更新于