java - Location Tracking Service slows app down -


for project needed app opens webpage in webview , @ same time tracks users location, if phone not active or app in front.

i got working , works should. location retrieved , server able work locations.

the problem is, if switch app after more 2 hours of background tracking, slowed down , response time in webview bad.

it seems if location service slowing down app. before service installed problem did not exist. cant explain, causes app lack, maybe can me.

this code of location service. gets called intent in oncreate of webview. locations gets written in string buffer gets uploaded server. (some empty override functions left out)

public class mylocationservice extends service {      double latservice;     double lngservice;     long timeservice;     float accservice;     long oldtime;     string hash = "";     string buffer = "";     private locationmanager lm;      @override     public int onstartcommand(intent intent, int flags, int startid) {         final handler handler = new handler();         final runnable r = new runnable() {             public void run() {                 locationupdates();                 if ((timeservice > 0) && (oldtime != timeservice)) {                     oldtime = timeservice;                     if (buffer.equals("")) {                         buffer += latservice + "," + lngservice + "," + accservice + "," + timeservice;                     } else {                         buffer += ";" + latservice + "," + lngservice + "," + accservice + "," + timeservice;                     }                     asynchttpclient client = new asynchttpclient();                     requestparams params = new requestparams();                     params.put("d", buffer);                     client.post("server.php", params, new texthttpresponsehandler() {                         @override                         public void onsuccess(int arg0, header[] arg1, string arg2) {                             system.out.println(arg2);                             buffer = "";                         }                     });                 }                 handler.postdelayed(this, 15000);             }         };         handler.postdelayed(r, 10);         return service.start_not_sticky;     }      public void locationupdates() {         loclistener loclist = new loclistener();         lm = (locationmanager) getsystemservice(context.location_service);         lm.requestlocationupdates(locationmanager.gps_provider, 0, 0, loclist);     }      public class loclistener implements locationlistener {         @override         public void onlocationchanged(location location) {             latservice = location.getlatitude();             lngservice = location.getlongitude();             timeservice = math.round(location.gettime() / 1000);             accservice = location.getaccuracy();         }     } } 

thanks in advance help.

i highly recommend using fused location provider priority_balanced_power_accuracy:

locationrequest request = locationrequest.create()         .setpriority(locationrequest.priority_balanced_power_accuracy)         .setinterval(polling_interval)         .setfastestinterval(polling_interval/2)         .setsmallestdisplacement(min_interval_meters); 

it designed provide in 40 meter range accuracy battery consumption <= 0.6%/hour.

also remember turn location listening off when no longer needed.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -