I suspect you need to update the Toast (which is a UI widget) on the UI thread. You do this by creating a Handler and posting a Runnable with the code you are using to update the Toast. If you don't, you run the risk of deadlock.
- Mike On May 7, 2:52 pm, Patricio Echague <patric...@gmail.com> wrote: > Hi all, my application read info from the GPS provider and shows it on > the screen. > The problem is that the locationListener is executed only twice for > some reason. > I tried to create another thread to print some other information at > the same time to verify that the application is still running, and it > was so. However, the listener that listens to the location change is > not invoked any more. > > To generate the GPS info i'm using DDMS manually and a .GPX file. > > Did any of you run into this issue? (I didn't find anything similar in > the discussion group) > > thanks > Patricio > > -------------------------------------- > > package com.apps.GpsApp; > > import java.io.IOException; > > import android.app.Activity; > import android.content.Context; > import android.location.Location; > import android.location.LocationListener; > import android.location.LocationManager; > import android.location.LocationProvider; > import android.os.Bundle; > import android.util.Log; > import android.widget.TextView; > import android.widget.Toast; > > public class GpsApp extends Activity { > > private TextView textView; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > // Set the layout for this activity. You can find it in res/ > layout/location_view.xml > setContentView(R.layout.location_view); > > // The text view for our text view, identified by its ID in > the XML file. > textView = (TextView) findViewById(R.id.text); > textView.setText("Ready to receive my location..."); > > final LocationManager locationManager = (LocationManager) > getSystemService(Context.LOCATION_SERVICE); > locationManager.requestLocationUpdates > (LocationManager.GPS_PROVIDER, 0, 0, new MyLocationListener > ()); > } > > private class MyLocationListener implements LocationListener { > > public void onLocationChanged(Location location) { > String lat = String.valueOf(location.getLatitude()); > String lon = String.valueOf(location.getLongitude()); > Log.e("GPS", "location changed: lat="+lat+", > lon="+lon); > > textView.append("\nLast location:" + lat + " " + lon); > > Toast.makeText(getBaseContext(), "Location changed : Lat: " + > lat + " Lng: " + lon, Toast.LENGTH_LONG).show(); > > } > > public void onProviderDisabled(String provider) { > } > > public void onProviderEnabled(String provider) { > } > > public void onStatusChanged(String provider, int status, > Bundle > extras) { > } > } > > } > > and the xml is: > > <?xml version="1.0" encoding="utf-8"?> > <manifest xmlns:android="http://schemas.android.com/apk/res/android" > package="com.apps.GpsApp" > android:versionCode="1" > android:versionName="1.0"> > > <uses-permission android:name="android.permission.ACCESS_LOCATION"/ > > <uses-permission android:name="android.permission.ACCESS_GPS"/ > > <uses-permission > android:name="android.permission.ACCESS_COARSE_LOCATION"/> > <uses-permission > android:name="android.permission.ACCESS_FINE_LOCATION"/> > <uses-permission > android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/> > <uses-permission > android:name="android.permission.ACCESS_MOCK_LOCATION"/> > <uses-permission > android:name="android.permission.CONTROL_LOCATION_UPDATES"/> > <uses-permission android:name="android.permission.INTERNET"/> > > <application android:icon="@drawable/icon" android:label="@string/ > app_name"> > <activity android:name=".GpsApp" > android:label="@string/app_name"> > <intent-filter> > <action android:name="android.intent.action.MAIN" /> > <category > android:name="android.intent.category.LAUNCHER" /> > </intent-filter> > </activity> > </application> > <uses-sdk android:minSdkVersion="2" /> > </manifest> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---