2021年3月2日星期二

Kotlin: How to call JobIntentService from Fragment?

I'm creating GPS tracking app. So I need to run this app at background (or foreground?). How can I call JobIntentService (SecondClass) class when I tap to button "Start" in Fragment (FirstClass)?

I looked for example at this code - but still I don't understand how to call JobIntentService class from Fragment class.

I try to call SecondClass like this (source):

val contentIntent = Intent(context, SecondClass::class.java)

But it ends with this error: java.lang.RuntimeException: Unable to instantiate service com...SecondClass: java.lang.InstantiationException: java.lang.Class<com...SecondClass> cannot be instantiated

https://stackoverflow.com/questions/66440759/kotlin-how-to-call-jobintentservice-from-fragment March 02, 2021 at 09:53PM

没有评论:

发表评论