Android Mqtt Service crash in NetworkChange Broadcast receiver -


i running mqttservice following working code service

public void reconnect() {      try     {                  // try connect         string id;         id=secure.getstring(getbasecontext().getcontentresolver(),secure.android_id);         mqttconnectoptions conn_opts= new mqttconnectoptions();         conn_opts.setcleansession(true);         conn_opts.setkeepaliveinterval(3600);         conn_opts.setusername(username);         conn_opts.setpassword(password);         mqttclient = new mqttclient(broker_url, id, new memorypersistence());         mqttclient.setcallback(this);         mqttclient.connect(conn_opts);                //subscribe subtopics of homeautomation         mqttclient.subscribe(topic);         // connectionstatus = mqttconnectionstatus.connected;         // inform app app has connected         //broadcastservicestatus("connected");      }     catch (mqttpersistenceexception e)     {                    // connectionstatus = mqttconnectionstatus.notconnected_unknownreason;        // broadcastservicestatus("unable connect");           }     catch (mqttsecurityexception e)     {                    // connectionstatus = mqttconnectionstatus.notconnected_unknownreason;        // broadcastservicestatus("unable connect");           }     catch (mqttexception e)     {      }   }`   

but when code executed in inner class broadcast receiver registered :

netconnreceiver = new networkconnectionintentreceiver();            intentfilter intentfilter = new intentfilter();         intentfilter.addaction(connectivitymanager.connectivity_action);         registerreceiver(netconnreceiver, intentfilter); 

it crashes. here simple broadcastreceiver code:

private class networkconnectionintentreceiver extends broadcastreceiver{      @override     public void onreceive(context ctx, intent intent)      {         // protect against phone switching off while we're doing         //  requesting wake lock - request minimum possible wake          //  lock - enough keep cpu running until we've finished         powermanager pm = (powermanager) getsystemservice(power_service);         wakelock wl = pm.newwakelock(powermanager.partial_wake_lock, "mqttservice");         wl.acquire();          if (isonline() && mqttclient!=null)          {             reconnect();         }          wl.release();      } } 

what did miss?the broadcastreceiver must inner class. tried many different solutions without success.

edit:

02-16 17:49:56.270: e/androidruntime(10554): fatal exception: main 02-16 17:49:56.270: e/androidruntime(10554): process: net.sprintbg.android.iptv, pid: 10554 02-16 17:49:56.270: e/androidruntime(10554): java.lang.runtimeexception: error receiving broadcast intent { act=android.net.conn.connectivity_change flg=0x4000010 (has extras) } in net.sprintbg.android.iptv.mqttservice$networkconnectionintentreceiver@94b35a4

if comment reconnect() going perfect. seems when call outside broadcastreceiver there missing ideas? regards


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -