enginar enginar - 6 months ago 49
Android Question

If value is null waiting for run function in android

I run a class LokasyonBulucu()

LokasyonBulucu lokasyonBulucu= new LokasyonBulucu();

I take two variable from this class lat and lon

lon= lokasyonBulucu.location.getLongitude();

but I want to waiting class found coordinates... because it take amount time.
if it find lat and lon I want to run this function

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

Answer Source

Use a for loop to check every second with a maximum number of seconds to wait. Check every second if the lat and lon are already found. If so execute the method and break out of the waiting loop:

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download