PendingIntent não envia extras de intenção

MinhasMainActicity começaRefreshService com umIntent que tem umboolean extra chamadoisNextWeek.

MinhasRefreshService faz umNotification que inicia meuMainActivity quando o usuário clica nele.

isto parece com isto:

    Log.d("Refresh", "RefreshService got: isNextWeek: " + String.valueOf(isNextWeek));

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.putExtra(MainActivity.IS_NEXT_WEEK, isNextWeek);

    Log.d("Refresh", "RefreshService put in Intent: isNextWeek: " + String.valueOf(notificationIntent.getBooleanExtra(MainActivity.IS_NEXT_WEEK,false)));
    pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    builder = new NotificationCompat.Builder(this).setContentTitle("Title").setContentText("ContentText").setSmallIcon(R.drawable.ic_notification).setContentIntent(pendingIntent);
    notification = builder.build();
    // Hide the notification after its selected
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(NOTIFICATION_REFRESH, notification);

Como você pode vernotificationIntent deve ter obooleanextraIS_NEXT_WEEK com o valor deisNextWeek que é colocado noPendingIntent.

Quando eu clico agoraNotification Eu sempre recebofalse como valor deisNextWeek

É assim que obtenho o valor noMainActivity:

    isNextWeek = getIntent().getBooleanExtra(IS_NEXT_WEEK, false);

Registro:

08-04 00:19:32.500  13367-13367/de.MayerhoferSimon.Vertretungsplan D/Refresh: MainActivity sent: isNextWeek: true
08-04 00:19:32.510  13367-13573/de.MayerhoferSimon.Vertretungsplan D/Refresh: RefreshService got: isNextWeek: true
08-04 00:19:32.510  13367-13573/de.MayerhoferSimon.Vertretungsplan D/Refresh: RefreshService put in Intent: isNextWeek: true
08-04 00:19:41.990  13367-13367/de.MayerhoferSimon.Vertretungsplan D/Refresh: MainActivity.onCreate got: isNextWeek: false

Quando eu inicio diretamente oMainActivity com umIntent com o "sNextValue" assim:

    Intent i = new Intent(this, MainActivity.class);
    i.putExtra(IS_NEXT_WEEK, isNextWeek);
    finish();
    startActivity(i);

tudo funciona bem e eu recebotrue quandoisNextWeek étrue.

O que eu faço errado que há sempre umfalse valor?

ATUALIZAR

isso resolve o problema:https://stackoverflow.com/a/18049676/2180161

Citar:

Minha suspeita é que, uma vez que a única coisa que muda na intenção é os extras, oPendingIntent.getActivity(...) método de fábrica é simplesmente reutilizar a intenção antiga como uma otimização.

Em RefreshService, tente:

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

Vejo:

http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_CANCEL_CURRENT

ATUALIZAÇÃO 2

Vejoresposta abaixo porque é melhor usarPendingIntent.FLAG_UPDATE_CURRENT.

questionAnswers(3)

yourAnswerToTheQuestion