1
我有一個應用程序,它具有4層/堆棧,像,Android通知,負荷只有當有一個以上的通知
首頁>> DetailPage >> MapPage >> ChatPage
最新的意圖
我設法創造每當我收到不同的聊天郵件的通知(請注意,每個會話都有其唯一的ID,說ChatId)
不同的談話中,我會ç reate使用ChatId通知爲requestCode中的PendingIntent
我現在面臨的問題是,每當我收到超過1個通知,說ChatId1至上,其次是ChatId2。然後,當我點擊了ChatId1的通知,將推出哪些是ChatId2最新的意圖,使得ChatPage加載的談話是ChatId2的對話。
的問題是,我怎樣才能讓這個,當我點擊ChatId1的通知,它加載的消息ChatId1,當點擊ChatId2,它加載ChatId2的消息。
下面是我創造我的通知
public void createLocalNotification(String meetingIdLong, String countryCode, String phoneNumber, String contactName, String chatMessage) {
// Prepare intent which is triggered if the
// notification is selected
Intent intent = new Intent(this, ChatLog.class);
long L = Long.parseLong(meetingIdLong);
int a = Integer.parseInt(meetingIdLong);
intent.putExtra("meetingId", L);
Intent intent1 = new Intent(this, HomePage.class);
Intent intent2= new Intent(this, MeetingDetailPage.class);
intent2.putExtra("meetingId", L);
Intent intent3 = new Intent(this, MapPage.class);
intent3.putExtra("meetingId", L);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ChatLog.class);
stackBuilder.addNextIntent(intent1);
stackBuilder.addNextIntent(intent2);
stackBuilder.addNextIntent(intent3);
stackBuilder.addNextIntent(intent);
PendingIntent pIntent = stackBuilder.getPendingIntent(a, PendingIntent.FLAG_UPDATE_CURRENT);
String notificationSound = _defPrefs.getString("pref_notification_tone", "");
NotificationCompat.Builder noti = new NotificationCompat.Builder(this)
.setContentTitle(contactName)
.setContentText(chatMessage)
.setSmallIcon(R.drawable.noti_smallicon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.noti_smallicon))
.setSound(Uri.parse(notificationSound))
.setDefaults(Notification.DEFAULT_VIBRATE)
.setNumber(++numberMsg)
.setAutoCancel(true)
.setContentIntent(pIntent);
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
String[] events = new String[6];
events [numberMsg - 1] = new String(chatMessage);
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle(contactName);
inboxStyle.setSummaryText(numberMsg + " new message(s)");
for (int i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
noti.setStyle(inboxStyle);
String isChatOpen, isChatOpenId;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
isChatOpen = preferences.getString("isChatOpen","");
isChatOpenId = preferences.getString("isChatOpenId","0");
if (!isChatOpenId.equals(meetingIdLong))
{
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(a, noti.build());
}
}
爲了啓動多個通知意圖,爲每個通知傳遞的id必須是唯一的,否則最新的將覆蓋其他通知意圖 –
@ Rat-a-tat-a-tatRatatouille是的,我傳遞的chatId是獨一無二的,我能夠接收到多個通知,就是說,當我點擊chatid 1的通知時,來自聊天ID 2的最新意圖最終被調用。 – munfai
可能你可以使用id本身來區分它嗎?像傳遞唯一的id,然後在活動的基礎上收到顯示id的數據 –