4
這裏的問題是:地理圍欄的PendingIntent與演員
服務是添加地理圍欄:
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);
}
...
}
正如你可以看到有意向它通過一些數據,並開始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
得到額外的?
'onHandleIntent'中是否只''triggeredGeofences' null或'deals'? – Sassa
如果我將交易對象作爲額外交易,則交易不爲空。如果我不那麼觸發Geofences不爲null。另外,我可以傳遞String對象作爲額外的,並且永久性會很好。當我試圖通過我自己的可序列化交易對象 – reel
,即使我有這個問題,這個問題已經解決了,你是否解決了這個問題? – satheeshwaran