0

我有一个 AsyncTask 用于检查加速度计数据。当我检测到加速度计给出更大的值时,我需要开始 GPS 记录。

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()
4

1 回答 1

1

AsyncTask 不在 Looper 线程上运行,因此存在问题,您可能希望使用处理程序,因为它们与 Looper 线程一起运行,因此不会发生此类错误。

于 2012-10-03T09:53:20.103 回答