0

I wrote the following code, in order to have callbacks on a thread when a location update is received (this is the main thread):

Handler handler; // this Handler is initialized in the following thread
Runnable r = new Runnable() {
    public void run() {
        Looper.prepare();
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                Log.d("MSG", msg.toString());
            }
        };
        Looper.loop();
    }
};
Thread t = new Thread(r);
t.start();


LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {
    public void onLocationChanged(Location location) {
        Log.d("UPD", "onLocationChanged");
    }
    [...]
}, handler.getLooper());

I am expecting to see MSG in Log when an update is received. Instead, while I see the UPD row, I cannot see MSG.

Then, what is the correct behavior of the requestLocationUpdates when I pass a looper?

Massimo
  • 3,436
  • 4
  • 40
  • 68
  • Nobody knows the role of that looper......... – Massimo Nov 18 '12 at 18:31
  • Are you from UBC? If so and this is for the final project xD : Edit: yeah you did use locationlistener. I'm not sure what you're using the handler for. Our project seems to work fine without a handler (though we haven't looked really closely). The onLocationChanged method updates the GeoPoint and calls update on the MapFragment class . – Raekye Nov 18 '12 at 18:52
  • No, I don't know what is UBC (I'm sorry). I am just trying to understand why I don't see callbacks on the handler to which the looper is linked... :( – Massimo Nov 18 '12 at 19:34
  • Ah sorry, (UBC is a university) we have a project which includes code really similar to that :P I had to ask – Raekye Nov 18 '12 at 20:06

0 Answers0