我正在開發包含廣播接收器的應用程序。 廣播接收機設置的通知的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