Android 我想每分钟更新一次位置
我想在每1分钟的时间间隔内获取当前位置,为此,我使用Timer类并在其中实现位置获取,但控件没有进入Timer块不知道为什么, 我尝试了很多代码,但每次都面临问题 我用了下面的代码 没有错误,也没有输出, 看起来控件并没有进入所需的代码块 有人能帮我一下我的代码出了什么问题吗Android 我想每分钟更新一次位置,android,timer,gps,location,handler,Android,Timer,Gps,Location,Handler,我想在每1分钟的时间间隔内获取当前位置,为此,我使用Timer类并在其中实现位置获取,但控件没有进入Timer块不知道为什么, 我尝试了很多代码,但每次都面临问题 我用了下面的代码 没有错误,也没有输出, 看起来控件并没有进入所需的代码块 有人能帮我一下我的代码出了什么问题吗 public class location3 extends Activity implements LocationListener { LocationManager locationManager;
public class location3 extends Activity implements LocationListener {
LocationManager locationManager;
Location location;
Timer timer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Handler handler = new Handler();
Timer timer = new Timer();
TimerTask doAsynchronousTask = new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
try {
//your method here
getLocation();
} catch (Exception e) {
}
}
});
}
};
timer.schedule(doAsynchronousTask, 0, 10000); //execute in every 1 minute
}
public void getLocation(){
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,1000,0,location3.this);
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
double lat=location.getLatitude();
double lon=location.getLongitude();
Toast.makeText(location3.this, lat+","+lon, Toast.LENGTH_LONG).show();
}
public void onLocationChanged(Location location){}
public void onProviderDisabled(String provider){}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
}
这是Eclipse中的Android吗?是的,如果你在计时器上加了一个断点,它的安卓系统就在eclipseSo中。时间表行它从来没有达到断点吗?