() getİntent Ekstralar her zaman NULL
Böyle özel bir Bildirim gösterir basit bir Android Uygulaması yazdım:
Context context = getApplicationContext();
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification( R.drawable.icon, title, System.currentTimeMillis());
Intent notificationIntent = new Intent( context, this.getClass());
notificationIntent.putExtra("com.mysecure.lastpage", "SECURECODE");
PendingIntent pendingIntent = PendingIntent.getActivity( context , 0, notificationIntent, 0);
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
notification.contentView = new RemoteViews(context.getPackageName(), R.layout.notifypbar);
notification.contentIntent = pendingIntent;
notification.contentView.setTextViewText(R.id.notifypb_status_text, text);
notification.contentView.setProgressBar(R.id.notifypb_status_progress, 100, (int)(100*progress), false);
manager.notify(104, notification);
Bu kod parçası SADECE bir KEZ uygulamam denir ve bir ilerleme çubuğu (doğru) ile bir bildirim görüntüler.
Bir kullanıcı bu bildirimi tıkladığında şimdi, benim uygulama onResume
olay işleme.
public void onResume()
{
super.onResume();
// TODO: Extras è SEMPRE NULL!!! impossibile!
Intent callingintent = getIntent();
Bundle extras = callingintent.getExtras();
ama ekstralar her zaman BOŞ.
Herhangi bir kombinasyonu denedim:
notificationIntent.putExtra("com.mysecure.lastpage", "SECURECODE");
ya
Bundle extra = new Bundle();
extra.putString(key, value);
notificationIntent.putExtra(extra);
ama getİntent().() getExtras her zaman döndürür NULL.
CEVAP
Bu senaryoyu
Yöntemi getIntent()
fırlatma etkinliği daha ÖNCE niyet verir.
Yani, bu aktivite KAPALI (sonlandırıldı) ve kullanıcı bildirimi tıkladığında, etkinliğin yeni bir örneğini çalıştırın ve 10* *olacaktır beklendiği gibi çalışır (Ekstralardeğil**11).
Ama eğer etkinlik "uyku" (arka planda) ve kullanıcı tıklama bildirimi, getIntent()
her zaman döndürür İLK hedefi o başladı, etkinlik ve niyet bildirimi.
Yani uygulama çalışırken bildirim hedefi yakalamak için, sadece bu kullanın
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
ve daha onNewIntent(Intent newintent)
geçersiz kılar.
Uygulama uyku devam ettiğinde, bir uygulama ilk kez çalıştırıldığında, getIntent()
kullanılabilir ve, onNewIntent
çalışır.
Ne zaman bir üye çağırma tanımsız davr...
Neden yapar .() Olabilirdi boş bir diz...
Null karma kodu her zaman sıfır olmalı...
Ne zaman Boole null değerleri kullanıl...
Neden >= yanlış zaman == null değer...