我正在开发包含广播接收器的应用程序。 广播接收机设置的通知的onReceive(),它包括一待决意图获取唤醒我的活动的意图
Intent updateHistoryIntent = new Intent(this, NotificationsHistory.class);
updateHistoryIntent.putExtra("test", 3);
PendingIntent updateHistoryPendingIntent
= PendingIntent.getActivity(this, 0, updateHistoryIntent, 0);
Notification notification
= new Notification(icon, contentTitle, System.currentTimeMillis());
notification.setLatestEventInfo(
context, contentTitle,
contentText, updateHistoryPendingIntent
);
在NotificationsHistory活性,我接收的onResume()与此意图:
int testInt = this.getIntent().getIntExtra("test", -1);
Aux.log("test : " + testInt);
它打印:
- 3:当活动被破坏
- -1:当活动正在睡觉
如果我正确阅读文档,this.getIntent()
将返回最初启动Activity的Intent,并且我描述的行为与预期的一样。
所以我的问题是:如何获得唤醒我的活动的意图?
非常感谢; (尤其是与以下组合: '保护无效onNewIntent(意图意图){setIntent(意向);}') – dimi 2011-05-22 18:12:04