while loop in main thread blocks listener updates?

by denzel » Thu, 05 Mar 2009 00:39:50 GMT

Sponsored Links

Take a look at the following code:

The first class is a locationmanager which holds the current and
previous location:

public class MyLocationManager implements LocationListener {
   private Location previousLocation;
   private Location currentLocation;

   private LocationManager locationManager;

   public MyLocationManager (Activity activity) {
      this.locationManager = (LocationManager)
(LocationManager.GPS_PROVIDER, 0, 0, this);

   public void onLocationChanged(Location location) {
      this.lastLocation = location;
      Log.v("LocationManager", "Lat: " + location.getLatitude() + " -
Lon: " + location.getLongitude());

   public void onProviderDisabled(String provider) {}

   public void onProviderEnabled(String provider) {}

   public void onStatusChanged(String provider, int status, Bundle
extras) {}


Th second class is the main activity which acts like a server and uses
the previous location to do something:

public class Example extends Activity {
   private MyLocationManager myLocationManager;

   public void onCreate(Bundle savedInstanceState) {

      myLocationManager = new MyLocationManager(this);
      while (true) {
         // do something (like some server functionality)
         Location loc = myLocationManager.getPreviousLocation();
         // do something

The problem is that myLocationManager doesn't retreive any updates for
the location. I think it has to do with this while-loop that blocks
the main-thread  by continously executing. And because
mylocationmanager is also running in the main thread, he cant't
retrieve his location updates.

Does somebody know how to deal with this? I think I have to make use
of threads somewhere, but I don't know where exactly.

Thanks in advance!

kind regards,


while loop in main thread blocks listener updates?

by denzel » Fri, 06 Mar 2009 03:55:30 GMT

 hanks for your response! My problem is solved!

On 4 mrt, 17:43, Romain Guy <romain...@google.com> wrote:

Sponsored Links

Other Threads

1. WebView content fit display screen!!!


I tried
but view crashed in 1.6 OS.

I calculate scale(webview.capturePicture()) but I cannot set it after
page loaded.

Is it any working solution for fitting webview content to display (1.6


2. Nexus One build error

I tried to do a build of all required images (make -j4) with the
kernel having been built based on android-msm-2.6.32, to be
installed on a Nexus One, and I'm getting:

error: out/target/product/passion/boot.img is too large (2439168 >
[2703360 - 270336])

Anyone run into this, and/or know how to get past this error?

unsubscribe: android-kernel+unsubscr...@googlegroups.com

3. How To Recover Missing Folders Option

4. Can't Find R.java

5. problem to run video stream in 1.5

6. What could cause ProgressDialog Spinner to stop spinning?

7. Android BT subsystem sleep