Get the Intent that woke up my activity
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);
Pendi开发者_JAVA百科ngIntent 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()
.
I think the problem is that when an activity is woken, getIntent() returns the intent that first started it.
精彩评论