android - Sending current location to server with locationlistener -


i have service within android app implements locationlistener keep track of users changing location.

every time location changed, want send server.

so, in onlocationchanged method fetching latitude , longitude. want send them server on network. hence, created new thread (as network operations not allowed on main thread). however, java.lang.nullpointerexception thread.

what should do?

here's code .....

    public class sservice extends service implements locationlistener{  public class localbinder extends binder {     splashservice getservice() {         return splashservice.this;     } }  @override public void oncreate() {     super.oncreate();     mnm = (notificationmanager)getsystemservice(notification_service);      //shows notification     shownotification();   }  @override public int onstartcommand(intent intent, int flags, int startid) {     log.i("sservice", "received start id " + startid + ": " + intent);        // sets parameters , location providers     setlocationparam();      return start_sticky; }  @override public void ondestroy() {     super.ondestroy();     // cancel persistent notification.     mnm.cancel(notification); }  @override public ibinder onbind(intent intent) {     return mbinder; }  // object receives interactions clients.  see // remoteservice more complete example. private final ibinder mbinder = new localbinder();    @override public void onlocationchanged(location location) {      // getting latitude of current location     latitude = location.getlatitude();      // getting longitude of current location     longitude = location.getlongitude();              log.v("sservice",latitude+"    "+longitude);      final smessage sm=new smessage("0", latitude, longitude,"");              // creates new thread     new sthread(sm).start();      }  @override public void onproviderdisabled(string provider) {     // todo auto-generated method stub  }  @override public void onproviderenabled(string provider) {     // todo auto-generated method stub  }  @override public void onstatuschanged(string provider, int status, bundle extras) {     // todo auto-generated method stub  } 

}


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -