android - date time change in onlocation changed -


ive created android app posts web services. supposed check users location , provide relative information gps update in terms of position , date time. rest of functions work fine date time remains same , have no idea why. insight prove helpful.

here of code.

locationlistener

    string lati, longi, alti, timestamp;     float speed;     int counter = 0;      date date = new date();     dateformat dateformat = new simpledateformat("yyyy-mm-dd't'hh:mm:ss'z'");       @override     public void onlocationchanged(location location)      {         // todo auto-generated method stub         log.d("location", "hello world");         lati = string.valueof(location.getlatitude());         longi = string.valueof(location.getlongitude());         alti = string.valueof(location.getaltitude());         speed = location.getspeed();                     timestamp = dateformat.format(date);         counter++;          requestinfo requestinfo = new requestinfo(sessionid, lati, longi, alti, speed, timestamp);         database.addrequest(requestinfo);          textview.settext("" + counter);      } 

the requestinfo class sets request web service. constructor provides info needed web service

you create instance date once, when object containing date created. therefore value stays unchanged. instead, move inside onlocationchanged method. this:

@override public void onlocationchanged(location location)  {     ...     date date = new date();     timestamp = dateformat.format(date);     ... } 

or can use calendar class , methods gettime() in here


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -