سؤال

I have created 3 activities. First is loginactivity to check login details.After Login is successfull it jumps to displayactivity which i used to show contacts of a person in a listview.After selecting any contact from listview it jumps to 3 activity which is messageactivity to show the chatting between 2 users. Now my question is where and how i implement messageListener So that i can show messages received from another user in messageactivity of a particular user?

هل كانت مفيدة؟

المحلول

I would recommend that you use a PacketListener in your XMPPConnection instead of MessageListeners for your individual Chats. You will receive all messages sent to you (of the type specified by the filter, most probably Chats) through this Listener and then you can do whatever you want whether it's the person you are chatting with or somebody else.

Something like this:

PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
connection.addPacketListener(new PacketListener() 
{
   public void processPacket(Packet packet) 
   {
      Message message = (Message) packet;
      String body = message.getBody();
      String from = message.getFrom();
   }
}, filter);

Together with this you probably have to use sendPacket instead of sendMessage but it's pretty much the same, you won't have to worry about individual Chat instances. I hope it serves the purpose.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top