这似乎是一个普遍的问题,我经历了所有相关的问题去,我能找到已经: 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