dengkai.chang
dengkai.chang
you should not throw IllegalArgumentException in getConnection method…… we can not catch this exception in main thread, it make my application crash many times……
@chintan-mishra yes,I have not do any network operate in main thread, but I need call mClient.connect(mConnectOptions,null, mConnectCallback) in main thread, but in this method , you called pool.excute(doConnect();), and throw...
`@Override public IMqttToken connect(MqttConnectOptions options, Object userContext, IMqttActionListener callback) throws MqttException { IMqttToken token = new MqttTokenAndroid(this, userContext, callback); connectOptions = options; connectToken = token; /* * The actual connection...
`/** * Actually do the mqtt connect operation */ private void doConnect() { if (clientHandle == null) { clientHandle = mqttService.getClient(serverURI, clientId,myContext.getApplicationInfo().packageName, persistence); } mqttService.setTraceEnabled(traceEnabled); mqttService.setTraceCallbackId(clientHandle); String activityToken = storeToken(connectToken);...
`public void connect(String clientHandle, MqttConnectOptions connectOptions, String invocationContext, String activityToken) throws MqttSecurityException, MqttException { MqttConnection client = getConnection(clientHandle); client.connect(connectOptions, null, activityToken); }`
`/** * Get the MqttConnection identified by this client handle * * @param clientHandle identifies the MqttConnection * @return the MqttConnection identified by this handle */ private MqttConnection getConnection(String clientHandle)...
`try { mClient.connect(mConnectOptions,null, mConnectCallback); } catch (Exception e) { e.printStackTrace(); LogUtil.e("连接到Mqtt服务器失败!"); doReconnect(false); }` this is my code, I just call connect(), but it throw exception and I cant catch it...
[https://github.com/eclipse/paho.mqtt.android/blob/b5d5e5ef91e846d39a365b8c561fa9670d34f691/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java#L588](url) [https://github.com/eclipse/paho.mqtt.android/blob/b5d5e5ef91e846d39a365b8c561fa9670d34f691/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java#L431](url)
I call mClient.connect() in A thread, but actually your code excuted and throw exception in B thread because your code excute by pool.excute() , so I cant catch any exception...
In my application, I register a network state change broadcast receiver ,when network disable, I disconnecte mqtt connection, and when network available, I will try to reconnect to the mqtt...