0
我正在开发一个使用谷歌播放服务的lib的Android应用程序。这个应用程序有一个谷歌地图,并使用locationManager来确定用户的位置。接下来找到谷歌地方并跟踪他们的谷歌方向。 在我的代码使用即使我的Android应用程序破坏,com.google.android.gms耗尽电池
@Override
protected void onDestroy(){
super.onDestroy();
}
但com.google.android.gms服务不停止(即使WIFI,3G和GPS关闭)和电池消耗。当我看到我的设备的电池使用它具有
CPU总使用2分钟3秒在背景
CPU使用率2分钟3秒
GPS10小时30分钟。
在我的代码需要位置更新的唯一情况是
@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));
}
和
// Getting LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location From GPS
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 2000, 0, this);
,但我认为,随着super.destroy(),其功能停止。
任何人都可以帮我解决我的问题吗? 在此先感谢!
谢谢。我会尝试你的解决方案! – Mixalis
我试过了您的代码,但仍然显示通知中显示“搜索GPS”的GPS图标。 – Rojesh
尝试在onDestroy方法上添加跟踪,可能尚未调用它。 – victoriza