powered by Jive Software

IncomingChatMessageListener does not work

When I use IncomingChatMessageListener, I find that I can only listen for messages once, and if I want to listen for messages again, I need to restart the application.But OutgoingChatMessageListener OutgoingChatMessageListener has no problems.Moreover, how can I manage the messages that have already been sent?

Unfortunately your post does not contain enough information to provide any assistance. Please have a look at How to ask for help, report an issue and possible solve the problem yourself · igniterealtime/Smack Wiki · GitHub

It’s like this

public class Login_or_Register extends AppCompatActivity {
        StanzaListener packetListener = new StanzaListener() {
            @Override
            public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException {
                Message message = (Message) packet;
                Looper.prepare();
                Toast.makeText(Login_or_Register.this, String.valueOf(chat.getXmppAddressOfChatPartner())+":  "+String.valueOf(message.getBody()), Toast.LENGTH_SHORT).show();
                Looper.loop();
            }
        };

        StanzaFilter stanzaFilter = new StanzaFilter() {
            @Override
            public boolean accept(Stanza stanza) {
                return true;
            }
        };
        login1.getConnection().addStanzaListener(packetListener,stanzaFilter);
}

or so it is

public class Login_or_Register extends AppCompatActivity {
      chatManager.addIncomingListener((from, message, chat1) -> {
            Looper.prepare();
            Toast.makeText(Login_or_Register.this, String.valueOf(from)+":  "+String.valueOf(message.getBody()), Toast.LENGTH_SHORT).show();
            Looper.loop();
        });
}

the listener can only be triggered once

I am using Smack 4.4.6 Android core

Long monitor contention with owner Smack DefaultReactor Thread #0 (5197) at void org.jivesoftware.smack.SmackReactor$Reactor.handleScheduledActionsOrPerformSelect()(SmackReactor.java:214) waiters=0 in void org.jivesoftware.smack.SmackReactor$Reactor.handleScheduledActionsOrPerformSelect() for 5.006s

Is it because of this problem?

I solved this problem because of the wrong use

Looper.prepare();
Lopper.loop();