1

我运行一个类 LokasyonBurucu()

LokasyonBulucu lokasyonBulucu= new LokasyonBulucu();
lokasyonBulucu.LokasyonBul(context);

我从这个类 lat 和 lon 中取两个变量

lat=lokasyonBulucu.location.getLatitude();
lon= lokasyonBulucu.location.getLongitude();

但我想等待班级找到坐标......因为这需要大量时间。如果它找到纬度和经度我想运行这个功能

new arkaPlanIsleri(kategori_id, lat , lon).execute();
4

1 回答 1

2

使用for循环检查每秒等待的最大秒数。lat如果和lon已经找到,请每秒检查一次。如果是这样,请执行该方法并跳出等待循环:

for(int i = 0; i < 10; i++) { //maximum 10 seconds to wait
    if(lat != null && lon != null) { //check if the lat and lon are already found
        new arkaPlanIsleri(kategori_id, lat , lon).execute();
        break; //stop the waiting loop
    }
    SystemClock.sleep(1000); //wait one second
}
于 2012-10-24T08:55:41.220 回答