내 MainActicity 시작 RefreshServiceA를 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
인용문:
내 의심은 Intent에서 변경되는 유일한 것은 Extras이기 때문에
PendingIntent.getActivity(...)Factory Method는 단순히 이전 의도를 최적화로 재사용하는 것입니다.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.