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