Chat thread

Hello,

I have some problems understanding the chatmanager.

I have this to receive all messages:

#1

conn.getChatManager().addChatListener(new ChatManagerListener() {

public void chatCreated(final Chat chat, final boolean createdLocally) {

chat.addMessageListener(new MessageListener() {

public void processMessage(Chat chat, Message message) {

String sender=message.getFrom();

String body=message.getBody();

if(body != null)

System.out.println("Received message: " + sender + " " + body);

}

});

}

});

Now I have a msg command line function:

#2

void msg(String to, String text)

{

Chat chat;

chat.sendMessage(text);

}

Lets say I have received a message first, so that a threadID has been created in #1.

Later I want to use msg() function to send a message to this JID.

As far as I understood I have to use the threadID which was created in #1. If I create a new thread in msg(), i will have 2 chats and 2 listeners for messages for the same participant.

So how do I find out the threadID in msg()?

Thanks.

Keep a reference to you chat when you were notified in the ChatListener and use it to send messages. It will already use the same thread ID as the incoming message.