I already have a lifecycleScope created in the MainActivity.
When I try to create a new lifecycleScope, I get an error:
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val LifecycleOwner.lifecycleScope: LifecycleCoroutineScope defined in androidx.lifecycle
I don’t know what to try.
In your first code snippet, you have:
class MainActivity : AppCompatActivity()
In your second code snippet, you have:
class UniversityDetails : Activity()
That is the source of your difficulty. Change the second code snippet to be:
class UniversityDetails : AppCompatActivity()
lifecycleScope
is an extension property of LifecycleOwner
. Activity
does not implement LifecycleOwner
, but AppCompatActivity
does.
UniversityDetails isn’t AppCompatActivity.