By using LifecycleObserver included in Android Jetpack (formarly Android Architecture Components), lifecycle can be monitored outside Activity / Fragment.

class MainActivity : AppCompatActivity() {

private val myLifecycleObserver = MyLifecycleObserver()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

lifecycle.addObserver(myLifecycleObserver)
}

override fun onDestroy() {
super.onDestroy()

lifecycle.removeObserver(myLifecycleObserver)
}
}

In this case, MyLifecycleObserver class monitores the lifecycle. In onCreate, the instance of MyLifecycleObserver class is added to observeres. Also, in onDestroy, it is removed from observers.

MyLifecycleObserver class implements LifecycleObserver. @OnLifecycleEvent annotation enables monitoring lifecycle. Any method name is OK.

class MyLifecycleObserver: LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
fun onCreate() {
Timber.i("onCreate")
}

@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onStart() {
Timber.i("onStart")
}

@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
fun onResume() {
Timber.i("onResume")
}

@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
fun onPause() {
Timber.i("onPause")
}

@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun onStop() {
Timber.i("onStop")
}

@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroy() {
Timber.i("onDestroy")
}
}

Done. Then we can monitor the Android lifecycle outside Activity / Fragment.