我应该如何在onCreate函数中每间隔5秒执行一次time()函数?我是Android的新手,希望得到帮助 =) ... 我想要在onCreate中每5秒执行一次time()函数。
public void onCreate(Bundle savedInstanceState) {
time(); //<-- How can i execute this every 5 seconds.
}
private void time() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
int success;
gps = new GPSTracker(AdminMenu.this);
if(gps.canGetLocation()){
tmplat=latitude;
tmplong=longitude;
// new InsertUser1().execute();
}
else{
gps.showSettingsAlert();
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("LATTTTT" + tmplat);
System.out.println("LONGGGGGGGG" + tmplong);
}
}, 5000); // 5 sec
}
任何帮助都将不胜感激...