Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!