If I add the following code snippet to a "normal" fragment it gets started and cancelled as expected when navigating to and from the fragment, but if I add this to fragment inside a view pager 2 it is not cancelled even though the fragmens onPause
method is invoked. Is this by design or am I missing something?
lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
try {
while (isActive) {
println("Fragment alive....")
delay(1000)
}
} catch (ex: CancellationException) {
println("Cancelled fragment...")
throw ex
}
}
}