我在创建全球定位系统追踪应用。所以我需要在后台(或前台?)运行这个应用程序。在点击Fragment (SecondClass)中的"Start“按钮时,如何调用JobIntentService (FirstClass)类?
例如,我查看了this code --但我仍然不明白如何从片段类调用JobIntentService类。
我尝试这样调用SecondClass (source):
val contentIntent = Intent(context, SecondClass::class.java)
但它以这个错误结束:java.lang.RuntimeException: Unable to instantiate service com...SecondClass: java.lang.InstantiationException: java.lang.Class<com...SecondClass> cannot be instantiated
发布于 2021-03-03 13:05:00
context?.run {
JobIntentService.enqueueWork(
applicationContext,
SecondClass::class.java,
100,// your id
Intent(applicationContext, SecondClass::class.java)
)
}不要忘记以这种方式在清单中声明服务
<service
android:name=".SecondClass"
android:permission="android.permission.BIND_JOB_SERVICE" />https://stackoverflow.com/questions/66440759
复制相似问题