I have following problem. I have this implementation of my Thread with Looper.
public class GeoLocationThread extends Thread{
public Handler handler;
private General general;
public void run(){
Looper.prepare();
handler = new IncomingHandler(general);
Looper.loop();
}
public GeoLocationThread(General general){
this.general=general;
}
private static class IncomingHandler extends Handler{
private final WeakReference<General> mService;
IncomingHandler(General service) {
mService = new WeakReference<General>(service);
}
@Override
public void handleMessage(Message msg)
{
General service = mService.get();
if (service != null) {
Location location=service.getLl().getLocation();
if(location.getAccuracy()<40){
service.setOrigin(new GeoPoint((int) (location.getLatitude() * 1E6),(int) (location.getLongitude() * 1E6)));
}
}
}
}
}
and i would like to do the following:
GeoLocationThread locationThread=new GeoLocationThread(this);
locationThread.start();
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll, locationThread.handler.getLooper());
Where lm is LocationManager. From my log and testing I am able to say that locationThread.handler.getLooper()
returns null instead of the Looper.
I don't know why it is null. I have tried to call locationThread.isAlive()
which has returned true. I have also tried to get locationThread.handler;
which I know is not null.
I have also done the lot of googling, but I haven't found more than the documentaion.
Thank you very much in advance for your answers.