PendingIntent не отправляет дополнения Intent

мойMainActicity начинаетсяRefreshService сIntent который имеетboolean дополнительно называется.isNextWeek

мойRefreshService делаетNotification который начинает мойMainActivity когда пользователь нажимает на него.

это выглядит так:

    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);

Как вы можете видетьnotificationIntent должен иметьbooleanдополнительныйIS_NEXT_WEEK со значениемisNextWeek который помещен в.PendingIntent

Когда я нажимаю сейчас этоNotification Я всегда получаюfalse как значениеisNextWeek

Так я получаю значение в:MainActivity

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

Журнал:

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

Когда я непосредственно начинаюMainActivity сIntent с ìsNextValue` как это:

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

все работает нормально и я получаюtrue когдаisNextWeek является .true

Что я делаю неправильно, что всегда естьfalse значение?

ОБНОВИТЬ

это решает проблему:https://stackoverflow.com/a/18049676/2180161

Цитата:

Я подозреваю, что, поскольку в Намерении меняется только то, чтоPendingIntent.getActivity(...) Фабричный метод просто повторно использует старое намерение в качестве оптимизации.

В RefreshService попробуйте:

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

Увидеть:

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

ОБНОВЛЕНИЕ 2

Увидетьответ ниже почему лучше использовать.PendingIntent.FLAG_UPDATE_CURRENT

Ответы на вопрос(3)

Ваш ответ на вопрос