The docs state: >The calling thread must be a Looper thread such as the main thread of the >calling Activity. http://developer.android.com/intl/de/reference/android/location/LocationManager.html#requestLocationUpdates%28java.lang.String,%20long,%20float,%20android.location.LocationListener%29
Doing a quick test using a HandlerThread to take care of that works fine on my Droid ( http://pastebin.com/8fr39Xzv ): public class TestGPSOnSecondThread extends Activity { private final LocationListener mLocationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { Log.i("TestGPSOnSecondThread", "onLocationChanged, location = " + location); } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }; private HandlerThread mThread; private LocationManager mLocationManager; @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } @Override protected void onResume() { super.onResume(); mThread = new HandlerThread("GPS Thread"); mThread.start(); new Handler(mThread.getLooper()).post( new Runnable() { @Override public void run() { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener); } }); } @Override protected void onPause() { super.onPause(); mLocationManager.removeUpdates(mLocationListener); mThread.getLooper().quit(); } } Although calling Looper.prepare() before requesting updates and then Looper.loop() after would probably work fine too. If you need the thread to be doing something other than looping/processing messages, you could just make another thread for this that receives updates and communicates with the Bluetooth one. On Mar 12, 12:40 am, ian <[email protected]> wrote: > I have been working on this issue for almost two weeks now, I am > really stuck on it. > > I have a bluetooth thread started that handles the bluetooth request. > Once the connection is made the thread is killed and a Connected > Thread is started. Once the Connected Thread is started I want to turn > on GPS so I can start feeding the GPS data through the output of the > bluetooth. The problem is, I can't get GPS to start in a seperate > thread other than the main Activity. I don't want that to happen as I > would like to have this run in the background and not be dependent on > the main Activity. > > I have tried turning on the GPS from inside the Connected Thread but > that always leads to a RunTimeException. > > Any ideas on how to get GPS to run in a thread? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

