Android Jetpack架构之LifecycleService
作者:互联网
一、LifecycleService的用途?
解耦系统组件Service的生命周期。
LifecycleService继承自Service。
二、示例
MyServiceObserver类:
class MyServiceObserver : LifecycleObserver { }
MyService类:
class MyService : LifecycleService() { private val _observer: MyServiceObserver = MyServiceObserver() init { lifecycle.addObserver(_observer) } override fun onDestroy() { super.onDestroy() lifecycle.removeObserver(_observer) } }
标签:LifecycleService,observer,Jetpack,Service,MyServiceObserver,MyService,Android,cl 来源: https://www.cnblogs.com/naray/p/15196710.html