Can’t putExtra in Intent in ViewModel


I’m trying to do a putExtra in a ViewModel but I get this error:

None of the following functions can be called with the arguments supplied.

This is my code:

   val intent  Intent(context,
   intent.action  MyService.ACTION_ONE
   intent.putExtra("data", mydata)
   ContextCompat.startForegroundService(context, intent)

Why I can’t do putExtra?


You cannot pass LiveData<Int> in an Intent extra. You could pass the current Int value (mydata.value) as an Intent extra, if you wanted.

Answered By – CommonsWare

Leave a Comment