我正在开发一个包含广播接收器的应用程序。 广播接收器设置onReceive()通知,其中包括待处理的Intent
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 Activity中,我在onResume()中收到此Intent:
int testInt = this.getIntent().getIntExtra("test", -1);
Aux.log("test : " + testInt);
打印:
如果我正确阅读了文档,this.getIntent()
将返回最初启动Activity的Intent,并且我描述的行为符合预期。
所以我的问题是:我怎样才能获得唤醒我活动的意图?
答案 0 :(得分:4)
当活动正在睡觉时
活动不睡觉。我假设你的意思是活动在后台。
如何获得唤醒我活动的Intent?
将FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP
作为标记添加到Intent
。然后,您的活动会通过onNewIntent()
将Intent
传递给它。
答案 1 :(得分:1)
我认为问题是当一个活动被唤醒时,getIntent()会返回首次启动它的意图。