gpt4 book ai didi

android - Geofence Transition onHandleIntent 是背景,但 Oreo 会允许吗?

转载 作者:行者123 更新时间:2023-11-29 02:34:01 25 4
gpt4 key购买 nike

对于 Oreo,在处理 onHandleIntent() 中的地理围栏转换事件时,我们是否需要立即启动前台服务,或者我们是否可以在 onHandleIntent() 函数中处理所需的工作(我的理解是在后台运行,但在 Oreo 中不应被允许):

public class GeofenceTransitionsIntentService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
//Do work here...
}
}

对比

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
}
}

谢谢!

最佳答案

改用JobIntentService(在 Kotlin 中):

class GeofenceTransitionsIntentService : JobIntentService() {
override fun onHandleWork(intent: Intent) {
val geofencingEvent = GeofencingEvent.fromIntent(intent)
// ...
}
}

关于android - Geofence Transition onHandleIntent 是背景,但 Oreo 会允许吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48084642/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com