我有一個程序可以在其中調用通知。通知,如果你把它拉下來,就會啓動一個新的活動。來自通知的Android刷新活動
mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.stat_sys_secure_green;
CharSequence tickerText = "Browser Security Enabled";
long when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Browser Security";
CharSequence contentText = "Security Vulnerability Detected";
Intent notificationIntent = new Intent(this, PrivacyMessage.class);
//Test Extra
notificationIntent.putExtra("Primary Key", "Primary Text");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(HELLO_ID, notification);
問題出現在代碼後面,當我想刷新次要活動。主要活動應該能夠動態地更改其中的額外內容。我試圖通過啓動一個新的意圖來做到這一點。
CharSequence contentTitle = "Browser Security";
CharSequence contentText = "Test New Notification";
Intent intent = new Intent(this, PrivacyMessage.class);
notification.icon = R.drawable.stat_sys_secure_orange;
intent.putExtra("Test Thing", "Test Value");
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent cI = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(getApplicationContext(), "New Title", "NewText", cI);
mNotificationManager.notify(HELLO_ID, notification);
現在,當我執行的代碼,新通知標題彈出,圖標顏色的變化,和下拉反映新標題和附加信息。但是,當我點擊它時,它不會以新的意圖啓動活動。相反,它只是將舊的活動與舊的演員混爲一談。我嘗試了FLAG_ACTIVITY_CLEAR_TOP和FLAG_ACTIVITY_NEW_TASK,但似乎都沒有清除舊的輔助活動並創建了新的輔助活動。有關我如何做到這一點的任何想法?
對不起,因爲我的誤解,但是你想發起一個沒有歷史的新活動,或者你希望舊活動在前臺並刷新其狀態? – mdelolmo
我希望當按下通知時舊的活動會到達前臺,但需要更新一個新的意圖。 – Lark
你能幫我解決我的問題嗎? http://stackoverflow.com/questions/20149685/android-notification-refresh-activity –