0

I have a AsyncTask where it checks for the Accelerometer data. When ever i detects that Accelerometer is giving larger values i need to start the GPS recording.

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); 

How to make this running? The errors i get are

error occured while executing doInBackground()
Can't create handler inside thread that has not called Looper.prepare()
dinesh707
  • 12,106
  • 22
  • 84
  • 134
  • why do you need to make this using AsyncTask? If you really want to use it within your AsyncTask, use it inside onPreExecute() so it'll launched on the UI thread – ColdFire Oct 03 '12 at 09:56
  • Check this link http://stackoverflow.com/questions/6961611/android-requestlocationupdates-throws-exception – Antrromet Oct 03 '12 at 09:57

1 Answers1

1

AsyncTask doesn't run on the Looper thread and hence the problem, You may want to use Handlers as they run with the Looper thread and hence such errors wont occur.

Royston Pinto
  • 6,681
  • 2
  • 28
  • 46