Cant launch new coroutine

I already have a lifecycleScope created in the MainActivity.
class 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
class UniversityDetails

I don’t know what to try.

  • 2

    UniversityDetails isn’t AppCompatActivity.

    – 

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.

Leave a Comment