Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
How to implement callbacks properly

I have two objects that needs callback implementation, what if both objects need different implementation? if i implement it at class level by implement keyword, interface methods only appear once in that activity, also If I'm calling both callback on the same object it only execute first callback, here is my code: same object but different implementation of interface method, in this case only the first callback executed that called first

client.setCallback(new MqttCallback() {
                @Override
                public void connectionLost(Throwable cause) {

                }

                @Override
                public void messageArrived(String topic, 
                    MqttMessage message) throws Exception {

                }

                @Override
                public void deliveryComplete(IMqttDeliveryToken token) {


                    try {
                        MqttMessage message = token.getMessage();

                    } catch (MqttException e) {
                        e.printStackTrace();
                    }


                }
            });

same object different implementation:

client.setCallback(new MqttCallback() {
                    @Override
                    public void connectionLost(Throwable cause) {

                    }

                    @Override
                    public void messageArrived(String topic, 
MqttMessage message) throws Exception {
                        tv.append(message.toString());
                        Log.i("MainActivity", " Mesages" + message);

                    }

                    @Override
                    public void deliveryComplete(IMqttDeliveryToken token) {
                    }
                });
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda