這似乎是一個普遍的問題,我經歷了所有相關的問題去,我能找到已經: Activity isn't picking up new intent,Why extra data (integer) is not sent in android notification intent?,Notification passes old Intent Extras,Can't put extras for an intent in notification,android pending intent notification problem;但仍然無法弄清楚。意圖沒有額外
問題是一樣的。我用PendingIntent設置了一個通知,其中攜帶了一些額外的信息,但我不知道它的另一面。
下面是用於生成通知的代碼:
Notification notification = new Notification(R.drawable.icon, getResources().getString(R.string.notification_ticker), System.currentTimeMillis());
notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
Intent start_test = new Intent(this, MyActivity.class);
start_test.putExtra("start_test", true);
start_test.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pi = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), start_test, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(this, getResources().getString(R.string.notification_title), getResources().getString(R.string.notification_content, expired), pi);
nm.notify(NOTIFICATION_ID, notification);
而在另一側上:
boolean start_test=getIntent().getBooleanExtra("start_test", false);
束實際上不存在(getExtras()返回null)。
我試過PendingIntent.getActivity
(FLAG_UPDATE_CURRENT
,FLAG_CANCEL_CURRENT
,FLAG_ONE_SHOT
)的不同標誌,這些都沒有幫助。
如上代碼所示,我用getCurrentMillis確保的RequestID變化....
還發現,在MyActivity,onCreate
和onNewIntent
沒有得到調用。只有onResume
是。即使FLAG_ACTIVITY_NEW_TASK
已設置...?
我錯過了很簡單的東西嗎?
如果你只想把一個額外然後用'Bundle'忘記。只需使用'new_intent.putExtra(「start_test」,真)'然後在另一端只使用'getIntent.getBooleanExtra(「start_test」,假)' – Squonk 2012-07-18 22:32:28
是的,我想這樣也,它並沒有改變任何東西...仍然沒有得到它在另一邊 – Matthieu 2012-07-18 22:43:38
當這種情況發生時,你的應用程序是否正在運行(或在後臺)?活動堆棧頂部是否有「MyActivity」? – 2012-07-19 14:38:13