With Oreo, when handling geofence transition event in onHandleIntent() are we required to start immediately a Foreground service or can we handle needed work inside onHandleIntent() function (which my understanding runs in the background but should not be allowed in Oreo):
public class GeofenceTransitionsIntentService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
//Do work here...
}
}
vs.
public class GeofenceTransitionsIntentService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
Intent startIntent = new Intent(this, ForegroundServices.class);
this.startForegroundService(startIntent); //and do needed work
//inside the Foreground service
}
}
Thanks!
Use a JobIntentService instead (in Kotlin):
class GeofenceTransitionsIntentService : JobIntentService() {
override fun onHandleWork(intent: Intent) {
val geofencingEvent = GeofencingEvent.fromIntent(intent)
// ...
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.