Android track应用程序导致设备过热
我开发了一个android应用程序,每10秒使用GPS获取当前位置,并使用socket将其发送到服务器。为了实现这一点,我使用postDelayed方法不断获取当前位置并将其发送到服务器Android track应用程序导致设备过热,android,gps,location,Android,Gps,Location,我开发了一个android应用程序,每10秒使用GPS获取当前位置,并使用socket将其发送到服务器。为了实现这一点,我使用postDelayed方法不断获取当前位置并将其发送到服务器 myRunnable = new Runnable() { @Override public void run() { Location mCurrentLocation =getCurrentLocation(); if(mCurrentLocation
myRunnable = new Runnable() {
@Override
public void run() {
Location mCurrentLocation =getCurrentLocation();
if(mCurrentLocation != null)
sendCurrentLocationToServer(mCurrentLocation);
Handler.postDelayed(this, 10000);
}};
public Location getCurrentLocation(){
Location currentLocation = myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
return currentLocation;
}
但是这个代码会使设备过热,并快速消耗电池,有没有其他方法可以达到同样的效果并降低过热
首先谢谢,不要使用getLastKnownLocation。它不仅通常返回null,而且循环调用它是一种效率极低的方法。相反,requestLocationUpdates,当它有一个新位置时,它会给您打电话 第二,不要每10秒将位置发送到服务器。频繁发送会导致您的手机不断打开收音机(wifi或手机),这会导致您的发热问题。发送数据会产生热量。将其减少到大约每分钟一次,并随位置向上发送航向和速度数据。如果需要更精确的位置,服务器可以使用速度和航向以编程方式计算可能的位置(如果需要)。很可能你根本不需要