0
我有一個AsyncTask來檢查加速度計數據。當我發現加速度傳感器給出更大的值時,我需要啓動GPS記錄。如何從AsyncTask調用「requestLocationUpdates」
private LocationManager mlocManager;
private GPSLocationListener mlocListener;
..
mlocManager = (LocationManager)context.getSystemService(context.LOCATION_SERVICE);
mlocListener = new GPSLocationListener();
..
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 100, mlocListener);
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 100, mlocListener);
如何使其運行?我得到的錯誤是
error occured while executing doInBackground()
Can't create handler inside thread that has not called Looper.prepare()
爲什麼你需要使用AsyncTask來做到這一點?如果你真的想在你的AsyncTask中使用它,請在onPreExecute()中使用它,以便它在UI線程上啓動 –
檢查此鏈接http://stackoverflow.com/questions/6961611/android-requestlocationupdates-throws-exception – Antrromet