【发布时间】:2014-08-25 15:06:46
【问题描述】:
问题来了:
添加地理围栏的服务:
public class GeofenceService extends Service implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, LocationClient.OnAddGeofencesResultListener, LocationClient.OnRemoveGeofencesResultListener {
...
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "onConnected");
switch (action){
case ADD:
Log.d(TAG, "onConnected ADD");
locationClient.addGeofences(geofencesToAdd, getPendingIntent(), this);
break;
case REMOVE:
Log.d(TAG, "onConnected REMOVE");
locationClient.removeGeofences(geofencesToRemove, this);
break;
}
}
private PendingIntent getPendingIntent(){
Intent intent = new Intent().setClass(this, TransitionsIntentService.class);
intent.putExtra(EXTRA_DEALS, deals);
return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
...
}
如您所见,有 Intent 传递一些数据并启动 TransitionIntentService:
public class TransitionsIntentService extends IntentService {
...
@Override
protected void onHandleIntent(Intent intent) {
deals = (ArrayList<Deal>) intent.getSerializableExtra(GeofenceService.EXTRA_DEALS); //THIS CAN BE NULL
int transitionType = LocationClient.getGeofenceTransition(intent);
List<Geofence> triggeredGeofences = LocationClient.getTriggeringGeofences(intent); //THIS CAN BE NULL
List<String> triggeredIds = new ArrayList<String>();
for (Geofence geofence : triggeredGeofences) {
Log.d("GEO", "onHandle:" + geofence.getRequestId());
processGeofence(geofence, transitionType);
triggeredIds.add(geofence.getRequestId());
}
...
}
如果我尝试在 getPendingIntent 方法中放入额外的(...,交易),我会得到 List<Geofence> triggeredGeofences = LocationClient.getTriggeringGeofences(intent) == NULL。
如果我不通过额外的一切工作正常。
我怎样才能通过我的额外收入并仍然从LocationClient 获得额外收入?
【问题讨论】:
-
只有
triggeredGeofences为空,还是deals也在onHandleIntent中? -
如果我将 Deal 对象作为额外对象传递,则交易不为空。如果我不那么触发Geofences 不为空。另外,我可以将 String 对象作为额外的对象传递,一切都会好起来的。当我尝试传递自己的可序列化交易对象时,问题就出现了
-
即使我有这个问题,你有没有机会解决它?
标签: android google-play-services android-geofence