Here is the problem:
Service that add geofences:
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);
}
...
}
As you can see there is Intent which pass some data and starts 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());
}
...
}
If I try to putExtra(..., deals) in getPendingIntent
method I'v got List<Geofence> triggeredGeofences = LocationClient.getTriggeringGeofences(intent) == NULL
.
If I don't pass extra everything works fine.
How can I pass my extra and still get extra from LocationClient
?
triggeredGeofences
null, ordeals
too inonHandleIntent
? – Selffertilization