enviando extra para requestLocationUpdates intentService quebra as atualizações de local

Estou tendo problemas para enviar uma string extra com o meuPendingIntent que eu passo paraLocationServices.FusedLocationApi.requestLocationUpdates(GoogleApiClient client, LocationRequest request, PendingIntent callbackIntent).

Parece que o nome de usuário extra que estou colocando noIntent está mutilando o local querequestLocationUpdates está tentando entregar para o meuIntentService Comointent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED) retornanull.

EDITAR

Eu tentei fazer umaUser classe que implementaParcelable e colocando como um extra:

mRequestLocationUpdatesIntent.putExtra("username", new User(username));

e eu também tentei colocar oParcelable User dentro de umBundle conforme sugerido pelo comentário neste relatório de bughttps://code.google.com/p/android/issues/detail?id=81812:

Bundle userBundle = new Bundle();
userBundle.putParcelable("user", new User(username));
mRequestLocationUpdatesIntent.putExtra("user", userBundle);

no meu serviço:

Bundle userBundle = intent.getBundleExtra("user");
User user = userBundle.getParcelable("user");
String username = user.getUsername();

No entanto, nenhuma dessas abordagens fez diferença. Sempre que coloco algum extra em minha intenção, o local nunca é adicionado à intenção quando as atualizações ocorrem.

Eu configurei issoIntentService para lidar com atualizações de local:

public class LocationUpdateService extends IntentService {

    private final String TAG = "LocationUpdateService";

    public LocationUpdateService() {
        super("LocationUpdateService");
    }


    @Override
    protected void onHandleIntent(Intent intent) {

        Log.d(TAG, "onHandleIntent");

        Bundle extras = intent.getExtras();
        Log.d(TAG, "keys found inside intent: " + TextUtils.join(", ", extras.keySet()));

        String username = intent.getStringExtra("username");

        if (username != null) {
            Log.d(TAG, "username: " + username);
        } else {
            Log.d(TAG, "username: null");
        }

        if (!intent.hasExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED)) {
            Log.d(TAG, "intent does not have location :(");
        }

        Location location = intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);

        if (location == null) {
            Log.d(TAG, "location == null :(");
        }

        Log.d(TAG, "latitude " + String.valueOf(location.getLatitude()));
        Log.d(TAG, "longitude " + String.valueOf(location.getLongitude()));

        ...

    }


}

Quando o usuário clica em um botão, ostartLocationUpdates é chamado na minha atividade principal:

classe de atividade principal:

...

Boolean mLocationUpdatesEnabled = false;

protected void createLocationRequest() {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(LOCATION_UPDATE_INTERVAL);
    mLocationRequest.setFastestInterval(LOCATION_UPDATE_FASTEST_INTERVAL);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}

protected void startLocationUpdates() {

    Log.d(TAG, "startng location updates...");

    mLocationUpdatesEnabled = true;

    if (mLocationRequest == null) {
        createLocationRequest();
    }

    // create the Intent to use WebViewActivity to handle results
    Intent mRequestLocationUpdatesIntent = new Intent(this, LocationUpdateService.class);

    // create a PendingIntent
    mRequestLocationUpdatesPendingIntent = PendingIntent.getService(getApplicationContext(), 0,
            mRequestLocationUpdatesIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    // request location updates
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
            mLocationRequest,
            mRequestLocationUpdatesPendingIntent);

    Log.d(TAG, "location updates started");
}

protected void stopLocationUpdates() {

    Log.d(TAG, "stopping location updates...");

    mLocationUpdatesEnabled = false;

    LocationServices.FusedLocationApi.removeLocationUpdates(
            mGoogleApiClient,
            mRequestLocationUpdatesPendingIntent);

    Log.d(TAG, "location updates stopped");
}

Tudo isso funciona muito bem; Quando o usuário pressiona o botão,toggleLocationUpdates é chamado, que chamaLocationServices.FusedLocationApi.requestLocationUpdates que chama meuLocationUpdateService onde eu posso obter a localização.

O problema surge quando eu tentei colocar uma corda extra no meuIntent usando Intent.putExtra (String, String):

classe de atividade principal:

...
protected void startLocationUpdates(String username) {
    ....

    // create the Intent to use WebViewActivity to handle results
    Intent mRequestLocationUpdatesIntent = new Intent(this, LocationUpdateService.class);

    //////////////////////////////////////////////////////////////////
    //
    //  When I put this extra, IntentService sees my username extra
    //  but the parcelableExtra `location` == null :(
    // 
    //////////////////////////////////////////////////////////////////

    mRequestLocationUpdatesIntent.putExtra("username", username);
    ...
}
...

EDITAR Eu comecei a próxima frase como uma afirmação e não como uma pergunta: "Estou usando ..."

Estou usando a abordagem correta para enviar alguns dados extras para este tratamento de atualização de localIntentService ou existe uma maneira mais sensata de fazer isso?

Isso é um bug ou apenas uma documentação ruim?

questionAnswers(1)

yourAnswerToTheQuestion