java - Wait onLocationChanged(Location location) -


i need current location, , after - next code. how can wait while method has finished? onlocationchanged called automatically why have problem. has ideas how itmore correct? make stupid, in onlocationchanged() call onresume(), bad idea.

    @override public void onlocationchanged(location location) {      final location loc = location;      log.d("mylogs", "onchange2");     log.d("mylogs", "2" + loc.getlatitude() + "," + loc.getlongitude());     mylat = loc.getlatitude();     mylong = location.getlongitude();     onresume();  } 

you might want use asynctask that. see android find gps location once, show loading dialog answers. in onpreexecute can start dialog( starts before doinbackground called). means waiting till time can location , showing dialog. in doinbackground can location. after finishes onpostexecute called. can stop inside onpostexecute. can check if location not null , call other function inside onpostexecute if want.

this might 1 way. can learn basic example asynctask android example . can start reading documentation here , read how gps location using asynctask? .

some other similar helpful questions:

wait current location - gps - android dev

getting location instantly in android

hope helps.