Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few things... </p> <p>What's probably happening is your app is being resumed and not created the "second" time. If you want it to look for a new location every time the activity is viewed you'll want to move the following code into the <code>onResume()</code> method:</p> <pre><code>lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locationListener); } </code></pre> <p>You'll also want to make sure you unregister your LocationListener in the <code>onPause()</code> method. Something like this should do it:</p> <pre><code>@Override public void onPause() { lm.removeUpdates(locationListener); super.onPause(); } </code></pre> <p>It looks like you have a typo on this line:</p> <pre><code>locationListener = new mLocationListener(); </code></pre> <p>I think it should be:</p> <pre><code>locationListener = new myLocationListener(); </code></pre> <p>Also, as someone else mentioned, there's no reason to create a whole new class to act as your LocationListener. In fact, it'll burn up memory unnecessarily and on mobile devices memory is at a premium.</p> <p>The combination of all of the things above would leave your Activity looking something like this: </p> <pre><code>public class Whatever extends Activity implements LocationListener { private LocationManager lm; private LocationListener locationListener; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new mLocationListener(); } @Override public void onResume() { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, this); super.onResume(); } @Override public void onPause() { lm.removeUpdates(this); super.onPause(); } @Override public void onLocationChanged(Location loc) { if (loc != null) { TextView gpsloc = (TextView) findViewById(R.id.widget28); gpsloc.setText("Lat:"+loc.getLatitude()+" Lng:"+ loc.getLongitude()); } } @Override public void onProviderDisabled(String provider) { TextView gpsloc = (TextView) findViewById(R.id.widget28); gpsloc.setText("GPS OFFLINE."); } @Override public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload