【发布时间】:2012-10-03 17:56:21
【问题描述】:
我有一个 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()
【问题讨论】:
-
为什么需要使用 AsyncTask 来做这个?如果你真的想在 AsyncTask 中使用它,请在 onPreExecute() 中使用它,这样它就会在 UI 线程上启动
标签: android