|
28 | 28 | import org.eclipse.paho.client.mqttv3.MqttException; |
29 | 29 | import org.eclipse.paho.client.mqttv3.MqttMessage; |
30 | 30 | import org.eclipse.paho.client.mqttv3.MqttPersistenceException; |
31 | | -import org.eclipse.paho.client.mqttv3.MqttSecurityException; |
32 | 31 | import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; |
33 | 32 |
|
34 | 33 | import android.app.Service; |
@@ -111,15 +110,15 @@ public void setClientHandle(String clientHandle) { |
111 | 110 | } |
112 | 111 |
|
113 | 112 | //store connect ActivityToken for reconnect |
114 | | - private String connectActivityToken = null; |
| 113 | + private String reconnectActivityToken = null; |
115 | 114 |
|
116 | 115 | // our client object - instantiated on connect |
117 | 116 | private MqttAsyncClient myClient = null; |
118 | 117 |
|
119 | 118 | // our (parent) service object |
120 | 119 | private MqttService service = null; |
121 | 120 |
|
122 | | - private volatile boolean disconnected = true; |
| 121 | + private volatile boolean disconnected = false; |
123 | 122 | private boolean cleanSession = true; |
124 | 123 |
|
125 | 124 | // Indicate this connection is connecting or not. |
@@ -184,9 +183,8 @@ public void setClientHandle(String clientHandle) { |
184 | 183 | public void connect(MqttConnectOptions options, String invocationContext, |
185 | 184 | String activityToken) { |
186 | 185 |
|
187 | | - final String internel_invocationContext = invocationContext; |
188 | 186 | connectOptions = options; |
189 | | - connectActivityToken = activityToken; |
| 187 | + reconnectActivityToken = activityToken; |
190 | 188 |
|
191 | 189 | if (options != null) { |
192 | 190 | cleanSession = options.isCleanSession(); |
@@ -258,11 +256,6 @@ public void onFailure(IMqttToken asyncActionToken, |
258 | 256 |
|
259 | 257 | doAfterConnectFail(resultBundle); |
260 | 258 |
|
261 | | - // if connect fail ,try reconnect. |
262 | | - if(service.isOnline()){ |
263 | | - connect(connectOptions, internel_invocationContext,connectActivityToken); |
264 | | - } |
265 | | - |
266 | 259 | } |
267 | 260 | }; |
268 | 261 |
|
@@ -795,8 +788,6 @@ public void onFailure(IMqttToken asyncActionToken, |
795 | 788 | Log.getStackTraceString(why)); |
796 | 789 | } |
797 | 790 | service.callbackToActivity(clientHandle, Status.OK, resultBundle); |
798 | | - service.traceDebug(TAG,"Reconnect for connection lost"); |
799 | | - reconnect(); |
800 | 791 | // client has lost connection no need for wake lock |
801 | 792 | releaseWakeLock(); |
802 | 793 | } |
@@ -980,7 +971,7 @@ synchronized void reconnect() { |
980 | 971 | final Bundle resultBundle = new Bundle(); |
981 | 972 | resultBundle.putString( |
982 | 973 | MqttServiceConstants.CALLBACK_ACTIVITY_TOKEN, |
983 | | - connectActivityToken); |
| 974 | + reconnectActivityToken); |
984 | 975 | resultBundle.putString( |
985 | 976 | MqttServiceConstants.CALLBACK_INVOCATION_CONTEXT, null); |
986 | 977 | resultBundle.putString(MqttServiceConstants.CALLBACK_ACTION, |
@@ -1011,10 +1002,6 @@ public void onFailure(IMqttToken asyncActionToken, Throwable exception) { |
1011 | 1002 |
|
1012 | 1003 | doAfterConnectFail(resultBundle); |
1013 | 1004 |
|
1014 | | - //reconnect fail , try reconnect . check network in reconnect function; |
1015 | | - service.traceDebug(TAG,"Reconnect Fail,Reconnect!"); |
1016 | | - reconnect(); |
1017 | | - |
1018 | 1005 | } |
1019 | 1006 | }; |
1020 | 1007 |
|
|
0 commit comments