In the end I used AsyncTask, which helped me in order to sleep the app while I looked for the location.
private class LocationThread extends AsyncTask<Context, Void, Void> {
protected void onPreExecute() {
infogatherer.startLocationListener();
}
@Override
protected Void doInBackground(Context... params) {
while (!infogatherer.getGo()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(final Void unused) {
//Do whatever you wanna do after you get location
}
}
getGo is a boolean which whenever becomes true gives the location back
public class mylocationlistener implements LocationListener {
@Override
public void onLocationChanged(android.location.Location location) {
if(location != null){
Longitude = location.getLongitude();
Latitude = location.getLatitude();
lm.removeUpdates(ll);
go = true;
}
}
hope you understand the procedure. Cheers.