Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] [android.service] When I reconnect in onFailure function.The app crash.

At a quick glance, it looks like you are attempting to put the Android context object into the connect call. This is not what that field is for on  MqttAndroidClient.connect (Although it is confusingly named, it is usually used for storing some useful information of your choosing that is passed back to any callbacks as a result of a successful connect or failure. This is why in the API is is just an Object and nothing more specific). My guess is that this object is pretty large and is probably what's causing the out of memory error. Are you using the 1.0.2 release or the 1.0.3 SNAPSHOT?
 
Kind regards,
 
James Sutton
Software Engineer - IoT Foundation - MQTT Open Source Projects
Technical Trojan - Wimbledon Project

Phone: 01962 815438 | Extension: x372454
E-mail: 
Personal Website: www.jsutton.co.uk
Find me on:      
IBM

Hursley Park
HursleySO212JN
United Kingdom
 
IBM United Kingdom Limited Registered in England and Wales with number 741598 Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU
 
 
----- Original message -----
From: "zhangkai.gis"<zhangkai.gis@xxxxxxx>
Sent by: paho-dev-bounces@xxxxxxxxxxx
To: "paho-dev"<paho-dev@xxxxxxxxxxx>
Cc:
Subject: [paho-dev] [android.service] When I reconnect in onFailure function.The app crash.
Date: Thu, Mar 24, 2016 12:30 PM
 
Hi all,
When I failed to connect to mqtt server.I run into IMqttActionListener's onFailure function.Then I call below code.
String[] actionArgs = new String[0];ActionListener acListener = new ActionListener(this.context,ActionListener.Action.CONNECT,this.clientid,actionArgs);MqttConnectOptions connOpt = new MqttConnectOptions();connOpt.setConnectionTimeout(Constants.MQTT_CONN_IMEOUT);connOpt.setKeepAliveInterval(Constants.MQTT_KEEPALIVE_INTERVAL);connOpt.setCleanSession(false);this.mqttclient.setCallback(new MqttCallbackHandler(this.context,this.clientid));this.mqttclient.setTraceCallback(new MqttTraceCallback());try{    this.mqttclient.connect(connOpt,this.context, acListener);}catch (MqttException e){    e.printStackTrace();}
 
The app crash.the stack is
FATAL EXCEPTION: mainjava.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try againat java.lang.VMThread.create(Native Method)at java.lang.Thread.start(Thread.java:1029)at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:913)at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1306)at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:426)at com.example.zhangkai.gpstraker.NetWork.MqttConn.connect(MqttConn.java:55)at com.example.zhangkai.gpstraker.NetWork.ActionListener.onFailure(ActionListener.java:155)at org.eclipse.paho.android.service.MqttTokenAndroid.notifyFailure(MqttTokenAndroid.java:146)at org.eclipse.paho.android.service.MqttAndroidClient.simpleAction(MqttAndroidClient.java:1374)at org.eclipse.paho.android.service.MqttAndroidClient.connectAction(MqttAndroidClient.java:1325)at org.eclipse.paho.android.service.MqttAndroidClient.onReceive(MqttAndroidClient.java:1265)at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:137)at android.app.ActivityThread.main(ActivityThread.java:5103)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:525)at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)at dalvik.system.NativeStart.main(Native Method)
 
What should I in onFailure function
Thanks,
zhangkai
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
 
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


Back to the top