把那惊醒了我的活动意向 [英] Get the Intent that woke up my activity
问题描述
我正在开发包含广播接收器的应用程序。 广播接收机设置的通知的onReceive(),它包括一待决意图
意图updateHistoryIntent =新的意图(这一点,NotificationsHistory.class);
updateHistoryIntent.putExtra(测试,3);
PendingIntent updateHistoryPendingIntent
= PendingIntent.getActivity(此,0,updateHistoryIntent,0);
通知通知
=新的通知(图标,contentTitle,System.currentTimeMillis的());
notification.setLatestEventInfo(
的背景下,contentTitle,
contentText,updateHistoryPendingIntent
);
在NotificationsHistory活动,我收到这个意图在onResume()有:
INT testInt = this.getIntent()getIntExtra(测试,-1)。
Aux.log(测试+ testInt);
它打印:
- 3:当活动被破坏
- -1:当活动正在睡觉
如果我正确读取文档, this.getIntent()
将返回最初开始的活动,我所描述的行为是按预期的意图。
所以我的问题是:?我怎样才能像惊醒了我的活动的意图
在活动正在睡觉
活动不睡觉。我假设你的意思是,活动是在后台。
我怎样才能像惊醒了我的活动的意图是什么?
添加 FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP
作为标志,以你的意图
。然后,你的活动就会获得这个意图
传递给它通过 onNewIntent()
。
I'm developing an application that includes a broadcast receiver. The broadcast receiver sets a notification onReceive(), which includes a pending 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
);
In the NotificationsHistory Activity, I am receiving this Intent in onResume() with:
int testInt = this.getIntent().getIntExtra("test", -1);
Aux.log("test : " + testInt);
which prints:
- 3: when the activity was destroyed
- -1: when the activity was sleeping
If I read the docs correctly, this.getIntent()
will return the Intent that initially started the Activity and the behavior I described is as expected.
So my question is: How can I get the Intent that woke up my activity?
when the activity was sleeping
Activities don't sleep. I am assuming that you mean that the activity was in the background.
How can I get the Intent that woke up my activity?
Add FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP
as flags to your Intent
. Then, your activity will get this Intent
passed to it via onNewIntent()
.
这篇关于把那惊醒了我的活动意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!