Smack threads and Android threads

Hi there!

I’m newbie in this forum, but I’ve developed a XMPP Smack Android application and I’ve got some questions about smack behaviour and threads. Here I go:

I get from roster my contacts with their JID, and with these, I send a MAM stanza to get history, like that:

<iq type='get' id='downloadMessages'>
<query
xmlns='urn:xmpp:mam:tmp'>
<with>user@myserver.com</with>
<set
xmlns='http://jabber.org/protocol/rsm'>
<max>30</max>
<before/>
</set>
</query>
</iq>

With this, I receive on my StanzaListener every messages from this JID, what is ok, but it looks like if each message (stanza received) was in an new thread, so I can’t sort messages in arrive order. So, my question is as follows:

  • Is there any way to receive all MAM messages stanzas in order (within same thread) for every jid and every message within its jid?

Following this topic, I’d like to know if I can create many StanzaListener to group different kinds of calls. If I could, it will be cool to implements RxJava and add listeners to listen only determitates packets, and remove them when my operations have finished. Actually, I only have one StanzaListener (called MyPacketInterceptor) which is listening for every packets.

Thanks in advance!

Of course. I recommend to use Smack’s specialized API for MAM: MamManager. For example MamManager.queryArchive(Integer max).

Not that listeners can be synchronous and asynchronous. Synchronous means that the order will be stable, but you can easily build a deadlock if you don’t know what you are doing.