Problème synchronisation Thread()
Bonjour,
Mon but est d'afficher un progressDialog, tant que de nouvelles coordonnées GPS n'ont pas été trouvées.
Mes variables longitude et latitude étant initialisées à 0, je fais comme suit:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| // longitude = 0;
// latitude = 0;
// progressDialog.show()
Thread checkLocation = new Thread(new Runnable() {
public void run() {
Log.e("APP", "Lancé!");
while (latitude == 0 && longitude == 0) {
try {
synchronized(this) {
wait();
}
} catch (InterruptedException e) {
Log.e("APP", "Erreur Thread Loc.: " + e.getMessage());
}
}
Log.e("APP", "OK! " + longitude + "/" + latitude);
// envoi vers handler et progressDialog.dismiss();
}
});
checkLocation.start(); |
Et mon OnLocationChanged:
Code:
1 2 3 4 5 6 7 8 9
| LocationListener locListener = new LocationListener() {
@Override
public synchronized void onLocationChanged(Location loc) {
latitude = loc.getLatitude();
longitude = loc.getLongitude();
Log.i("APP", "changé: " + latitude + "/" + longitude);
notify();
}
} |
Mon LogCat part bien: "Lancé!"
Puis j'obtiens bien: "changé: xx/xx"
Mais jamais je vois le "OK!" final, à croire que le Thread reste en wait()...
Comment bien synchroniser tout ça?
Merci