eclipse / paho.mqtt.android

MQTT Android
Other
2.92k stars 880 forks source link

Error receiving broadcast Intent CONNECTIVITY_CHANGE MQTT #367

Open ManishAndroidIos opened 5 years ago

ManishAndroidIos commented 5 years ago

Please fill out the form below before submitting, thank you!

Android API Version Bug Seen on: API Version - 24

Android Version Bug Seen on: implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0' implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

Please also check that if you have found the bug in the Release version (1.1.1) that you check that it also exists in the Snapshot (1.1.2-SNAPSHOT) before raising a bug.

Description of Bug:

Stape 1: turn off internet wifi and mobile data connection dont close the app Stape 2: open the data or wifi connection the app will crash

Console Log output (if available):

2019-06-06 13:44:52.274 24799-24799/com.org.leorocuserapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.org.leorocuserapp, PID: 24799 java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } bqHint=1 (has extras) } in org.eclipse.paho.android.service.MqttService$NetworkConnectionIntentReceiver@f077463 at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:1195) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6682) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.Timer.cancel()' on a null object reference at org.eclipse.paho.client.mqttv3.MqttAsyncClient.stopReconnectCycle(MqttAsyncClient.java:1120) at org.eclipse.paho.client.mqttv3.MqttAsyncClient.reconnect(MqttAsyncClient.java:1057) at org.eclipse.paho.android.service.MqttConnection.reconnect(MqttConnection.java:1049) at org.eclipse.paho.android.service.MqttService.reconnect(MqttService.java:342) at org.eclipse.paho.android.service.MqttService$NetworkConnectionIntentReceiver.onReceive(MqttService.java:827) at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:1185) at android.os.Handler.handleCallback(Handler.java:751)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6682)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)  2019-06-06 13:44:58.424 24799-24810/com.org.leorocuserapp E/PowerManager: WakeLock finalized while still held: MQTT

aloz77 commented 5 years ago

Updating the client to 1.2.1 seems to fix this issue

implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.1'

nguyenvanquan7826 commented 4 years ago

I use mqttv3:1.2.1, But this issue continue.

BarretWu commented 4 years ago

I too , happen very frequently

FibonacciSpiral commented 4 years ago

Hey I solved this problem! For me, all I had to do was add the correct permissions. The app crashes when it tries to connect to the internet because it didn't have permission. I added these to the android manifest. Capture Read more about it here ->https://www.hivemq.com/blog/mqtt-client-library-enyclopedia-paho-android-service/

Morteza-Rastgoo commented 4 years ago

@FibonacciSpiral I already have all the permissions but the problem still exists on retrying the connection

kenmasumitsu commented 4 years ago

Updating the client to 1.2.4 seems to fix this issue

implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.4' https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client.mqttv3/1.2.4

panda912 commented 4 years ago

mqttv3-1.2.4 has fixed this issue.

    private void stopReconnectCycle() {
        String methodName = "stopReconnectCycle";
        // @Trace 504=Stop reconnect timer for client: {0}
        log.fine(CLASS_NAME, methodName, "504", new Object[] { this.clientId });
        synchronized (clientLock) {
            if (this.connOpts.isAutomaticReconnect()) {
                if (reconnectTimer != null) {
                    reconnectTimer.cancel();
                    reconnectTimer = null;
                }
                reconnectDelay = 1000; // Reset Delay Timer
            }
        }
    }