2012-10-03 36 views
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() 
+0

为什么你需要使用AsyncTask来做到这一点?如果你真的想在你的AsyncTask中使用它,请在onPreExecute()中使用它,以便它在UI线程上启动 –

+0

检查此链接http://stackoverflow.com/questions/6961611/android-requestlocationupdates-throws-exception – Antrromet

回答

1

的AsyncTask不弯针线,因此这个问题上运行,你可能想,因为他们与套口线运行,因此这样的错误不会发生使用的处理程序。