【发布时间】:2021-08-25 10:07:27
【问题描述】:
我可以成功扩展和调用JobIntentService的函数
enqueueWork(context, MessagesRetentionKotlin::class.java, UNIQUE_JOB_ID, work)
在 kotlin 中,但不在 Scala 中。在这里,我将分享我的扩展 JobIntentService 类的 Scala 代码,如果有人可以帮助我,那就太好了。谢谢。
class MessagesRetention(context: Context, work: Intent) extends MessagesRetentionTrait with JobIntentService{
override def onCreate():Unit= {
super.onCreate()
Log.d(TAG, "onCreate")
}
override def onHandleWork(intent: Intent):Unit= {
Log.d(TAG, "onHandleWork")
val input: String = intent.getStringExtra("inputExtra")
for (i <- 0 to 10) {
Log.d(TAG, "$input - $i")
if (isStopped) return
SystemClock.sleep(1000)
}
}
override def onDestroy():Unit= {
super.onDestroy()
Log.d(TAG, "onDestroy")
val serviceIntent = new Intent(this, MessagesRetentionImpl.getClass)
serviceIntent.putExtra("inputExtra", "Test")
MessagesRetention.enqueueWorkk(this, serviceIntent)
}
}
object MessagesRetention {
private val TAG = "MessagesRetention"
val UNIQUE_JOB_ID = 10101
def enqueueWorkk(context: Context, work: Intent):Unit= {
enqueueWork(context, MessagesRetentionImpl.getClass, UNIQUE_JOB_ID, work)
}
}
【问题讨论】:
标签: android scala kotlin service scala-collections