1. Looper.prepare();
2. Handler mHandler = new Handler() {
3. public void handleMessage(Message msg) {}
4. };
5. mHandler.post(gpsLocationListenerThread);
6. Looper.loop();
7.
我正在Thread
从AsyncTask
. 当我使用 1-6 中的代码调用它时,它会创建Thread
并运行它。但是AsyncTask
卡在那里。我需要在Thread
不阻塞我的AsyncTask
. 如何让它发生?
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);
}