paho.mqtt.android icon indicating copy to clipboard operation
paho.mqtt.android copied to clipboard

Error receiving broadcast Intent CONNECTIVITY_CHANGE MQTT

Open ManishAndroidIos opened this issue 5 years ago • 7 comments

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

  • [ ] Bug exists Release Version 1.1.1 (Java Repository Master Branch)
  • [ ] Bug exists in Snapshot Version 1.1.2-SNAPSHOT (Android Service Repository Master Branch)
  • [ ] Bug is just in the Sample Application.

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

ManishAndroidIos avatar Jun 06 '19 08:06 ManishAndroidIos

Updating the client to 1.2.1 seems to fix this issue

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

aloz77 avatar Sep 11 '19 07:09 aloz77

I use mqttv3:1.2.1, But this issue continue.

nguyenvanquan7826 avatar Oct 05 '19 10:10 nguyenvanquan7826

I too , happen very frequently

BarretWu avatar Dec 28 '19 07:12 BarretWu

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/

FibonacciSpiral avatar Jan 16 '20 03:01 FibonacciSpiral

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

Morteza-Rastgoo avatar Feb 02 '20 12:02 Morteza-Rastgoo

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

kenmasumitsu avatar May 27 '20 08:05 kenmasumitsu

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
			}
		}
	}

panda912 avatar Jun 29 '20 07:06 panda912