从Android O的IntentService迁移到JobIntentService的问题 [英] Issue Moving from IntentService to JobIntentService for Android O

查看:61
本文介绍了从Android O的IntentService迁移到JobIntentService的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Intent Service来监视Geofence转换.为此,我正在使用粘性服务的以下呼叫.

I am using Intent Service to monitor Geofence transition. For that I am using following call from a Sticky Service.

 LocationServices.GeofencingApi.addGeofences(
                    mGoogleApiClient,
                    getGeofencingRequest(),
                    getGeofencePendingIntent()
            )

和待处理的Intent调用过渡服务(IntentService),如下所示.

and the Pending Intent calls Transition service (an IntentService) like below.

  private PendingIntent getGeofencePendingIntent() {
        Intent intent = new Intent(this, GeofenceTransitionsIntentService.class);
        // We use FLAG_UPDATE_CURRENT so that we get the 
          //same pending intent back when calling addgeoFences()
        return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

Pre Oreo效果不错.但是,我必须将粘性服务转换为JobScheduler,并且需要将GeofenceTransitionsIntentService转换为JobIntentService.

This worked fine Pre Oreo. However, I had to convert my sticky service to a JobScheduler and I need to convert GeofenceTransitionsIntentService which is an intentService to JobIntentService.

已经说过,我不确定如何返回为JobIntentService创建一个PendingIntent,因为我需要为JobIntentService调用enqueueWork.

Having said that I am not sure how to return create a PendingIntent for JobIntentService, because I need to call enqueueWork for JobIntentService.

任何建议/指针将不胜感激.

Any suggestions/pointer would be appreciated.

推荐答案

按照@andrei_zaitcev的建议,我实现了我的自定义BroadCastReceiver并调用了Service的enqueueWork(),效果很好.

As @andrei_zaitcev suggested, I implemented my custom BroadCastReceiver and call enqueueWork() of the Service, which works perfectly.

这篇关于从Android O的IntentService迁移到JobIntentService的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆