1. Looper.prepare();
2. Handler mHandler = new Handler() {
3. public void handleMessage(Message msg) {}
4. };
5. mHandler.post(gpsLocationListenerThread);
6. Looper.loop();
7.
I'm calling a Thread
class from AsyncTask
. When i call it using code from 1-6, it creates the Thread
and runs it. But AsyncTask
get stucked there. I need to run this other Thread
without blocking my AsyncTask
. How to make it happen?
public GPSLocationListenerThread(Context context){
this.context = context;
mlocManager = (LocationManager)context.getSystemService(context.LOCATION_SERVICE);
mlocListener = new GPSLocationListener();
}
public void setHandler(Handler _h){
this.mHandler = _h;
}
public void run(){
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 100, mlocListener); // in 1000 mseconds or in 100m change
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 100, mlocListener); // in 1000 mseconds or in 100m change
//mHandler.getLooper().quit();
while (DataHolder.getDataHolderObject().isTripStarted()){
try {
this.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
mlocManager.removeUpdates(mlocListener);
}