SORU
3 AĞUSTOS 2013, CUMARTESİ


Pendingİntent Niyet göndermez ekstralar

MainActicity işe başlıyor boolean a ek isNextWeek olarak adlandırılan Intent 7**.

Benim RefreshService kullanıcı tıklattığında* *benim 13 başlatan Notification bir hale getirir.

bu şuna benzer:

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

Gördüğünüz gibi notificationIntent PendingIntent konur isNextWeek değeri ile booleanIS_NEXT_WEEK ekstra olmalıdır.

Ben Notification Bu şimdi tıklayın, her zaman isNextWeek değer false

Bu MainActivity: değer alıyorum

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

Günlük:

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

Ben doğrudan ìsNextValue Intent MainActivity başlayınca bu gibi:

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

her şey gayet iyi çalışıyor ve isNextWeek true true.

Ben her zaman false bir değeri olduğunu yanlış ne yapabilirim?

GÜNCELLEME

bu sorunu çözer: http://stackoverflow.com/a/18049676/2180161

Alıntı:

Benim şüphe tek şey, Niyet değişiyor beri, ekstralar, PendingIntent.getActivity(...) fabrika yöntemdir yeniden kullanma, eski niyet sadece bir iyileştirme.

RefreshService, deneyin:

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

Bkz:

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

CEVAP
3 AĞUSTOS 2013, CUMARTESİ


Yeni bir tane aldığınızda Intent Etkinlik onNewIntent(Intent) kılarak güncelleme gerekiyor sanırım. Etkinlik aşağıdakileri ekleyin:

@Override
public void onNewIntent(Intent newIntent) {
    this.setIntent(newIntent);

    // Now getIntent() returns the updated Intent
    isNextWeek = getIntent().getBooleanExtra(IS_NEXT_WEEK, false);        
}

Düzenleme:

Bu Etkinlik zaten niyet alındığında başlatılmışsa, yalnızca gerekli. Eğer etkinlik başladı (ve devam) niyeti ile olursa, o zaman sorun başka bir yerde ve benim önerim tamir olmayabilir.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • michaeljacksonVEVO

    michaeljacks

    2 EYLÜL 2009
  • MuscleProdigyTV

    MuscleProdig

    8 Ocak 2011
  • xiaoyu85

    xiaoyu85

    20 ŞUBAT 2010