2012-10-03 5 views
0

Accelerometer 데이터를 확인하는 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를이 루퍼 따라서 문제에서 실행되지 않습니다, 당신은 그들이 루퍼 스레드 실행 따라서 이러한 오류 못해 발생하는 핸들러를 사용할 수 있습니다.

관련 문제