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()); 
      } 

     } 
+0

为了启动多个通知意图,为每个通知传递的id必须是唯一的,否则最新的将覆盖其他通知意图 –

+0

@ Rat-a-tat-a-tatRatatouille是的,我传递的chatId是独一无二的,我能够接收到多个通知,就是说,当我点击chatid 1的通知时,来自聊天ID 2的最新意图最终被调用。 – munfai

+0

可能你可以使用id本身来区分它吗?像传递唯一的id,然后在活动的基础上收到显示id的数据 –

回答

1

使用

intent.setAction(Long.toString(System.currentTimeMillis())); 

你想成为唯一的每个意向的代码片段。它只是一个虚拟的动作,但它有帮助。