我正在使用基于此 Google 示例的地理围栏。但是,我发现除非我在谷歌地图或其他基于位置的应用程序中,否则地理围栏转换不会在后台准确发生。正因为如此,我试图把它JobIntentService
变成一个前台服务,它将接收它自己的定期位置更新。
有人可以解释它的生命周期JobIntentService
以及创建方法时调用方法的顺序吗?
请记住,我正在使用以下类:
class GeofenceBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
GeofenceTransitionsJobIntentService.enqueueWork(context, intent)
}
}
class GeofenceTransitionsJobIntentService : JobIntentService() {
companion object {
private const val JOB_ID = 573
// Convenience method
fun enqueueWork(context:Context, intent:Intent) {
enqueueWork(context, GeofenceTransitionsJobIntentService::class.java, JOB_ID, intent)
}
}
onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
// Make notification and start as a foreground service
return START_STICKY
}
onHandleWork(intent: Intent) {
// Handle the geofences
}