2010-07-05 25 views
8

我已閱讀了許多關於同一主題的帖子,並嘗試了所有給定的解決方案,但未獲得我想要的結果。 該方案應與來自通知額外開始的意圖:Android尚未從notificaion開始的意圖不會取代最後的

NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 

Intent notificationIntent = new Intent(context, myActivity.class); 
    notificationIntent.putExtra("someData", data); 

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 

mNotificationManager.notify(ID, notification); 

的問題是,當所示的新通知,加入到意圖的額外的是一樣的,在第一通知。我在意圖和待決意圖中與不同的標誌聯繫在一起,沒有結果。我錯了什麼? 如果我只是用一個按鈕啓動相同的活動(和相同的額外),一切都按照它應有的方式工作。

+0

可能重複[Android的不斷緩存我的意圖附加功能,如何聲明一個懸而未決的意圖,保持新鮮的額外?](http://stackoverflow.com/questions/3140072/android-keeps-caching-my-intents-extras-how-to-declare-a-pending-intent-那是 - ) – Pentium10 2010-07-05 13:18:15

+1

是的,事情是,我讀了這篇文章,還有一些,但他們都沒有工作f或者我。但是,在某種程度上,我設法解決了這個問題,並且很快就會在這裏發佈我的解決方案。 – Emil 2010-07-05 14:34:22

回答

9

我不知道爲什麼我有這樣的問題,讓這個工作。我用得到它正常工作標誌的組合是:

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 
       PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); 

我也刪除了所有創建notificationIntent時使用的標誌。

5

嘗試在AndroidManifest.xml文件添加一個屬性:

<activity ... android:launchMode="singleTop"/> 
0

嘗試設置請求代碼爲每個PendingIntent,它會工作的

PendingIntent pendingIntent = PendingIntent.getActivity(this, RandomInt, intent, 
       PendingIntent.FLAG_ONE_SHOT);