I’m new to Android. In my current project I’m using the asmack library to receive XMPP messages. In my MainActivity I have:
Connection connection; // from the asmack library
and
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
// HERE! is where I want to update the UI when I receive packets
}
}
The weird thing is when I parse the packet and simply call setText() on two labels. At first nothing happens, but when I touch a Button (hence calling some update routine) only the first label is updated.
Now, as far as I understood you’re supposed to use AsyncTask in such cases but this didn’t work out either.
Did I misunderstood some core concept? Can someone lead me to the right path?
The packet seems to be processed on a separate thread than the UI thread, which means the UI will not be updated immediately since you’re not manipulating it on its thread. Therefore, you should do something like this…