Even if my android app destroy, com.google.android.gms drain battery -
i developing android application use google-play-services-lib. app has google map , use locationmanager determine user location. next find google places , track google directions them. in code use
@override protected void ondestroy(){ super.ondestroy(); } but com.google.android.gms services dont stop (even if wifi, 3g , gps turn off) , battery drain. when see battery usage of device has
cpu total usage 2min 3sec
cpu usage in background 2min 3sec
gps 10 hours 30min.
in code situations require location update are
@override public void onlocationchanged(location location) { mlatitude = location.getlatitude(); mlongitude = location.getlongitude(); latlng latlng = new latlng(mlatitude, mlongitude); mgooglemap.movecamera(cameraupdatefactory.newlatlng(latlng)); mgooglemap.animatecamera(cameraupdatefactory.zoomto(12)); } and
// getting locationmanager object system service location_service locationmanager locationmanager = (locationmanager) getsystemservice(location_service); // creating criteria object retrieve provider criteria criteria = new criteria(); // getting name of best provider string provider = locationmanager.getbestprovider(criteria, true); // getting current location gps location location = locationmanager.getlastknownlocation(provider); locationmanager.requestlocationupdates(provider, 2000, 0, this); but thought super.destroy() functions stop.
can me problem? in advance!
you need remove updates. work in other thread try this:
@override public void ondestroy() { locationmanager.removeupdates(this); super.ondestroy(); }
Comments
Post a Comment