Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have a global point p that you're overwriting every call to updateList. Since you aren't creating a new point ever, this overwrites the old values. That means every element in your list will always have the most recent values, rather than the value at that time.</p> <p>Also, why are you using class variables everywhere rather than passing parameters to functions? I have a feeling you don't understand Java or references very well.</p> <p>Edit:</p> <p>Here's what your code should look like, with locals used correctly:</p> <pre><code>package com.example.pointkeeper; import java.util.ArrayList; import android.app.Service; import android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.util public class ServicePointKeeper extends Service implements LocationListener{ private LocationManager lm; ArrayList&lt;Point&gt; pt; private final static long TEMPO_DE_ATUALIZACAO = 1 * 60 * 1000 ; private final static float DISTANCIA_DE_ATUALIZACAO = 1 ; public void setGPS(){ Criteria criteria = new Criteria(); criteria.setAccuracy( Criteria.ACCURACY_FINE ); criteria.setAltitudeRequired(true); String provider = lm.getBestProvider(criteria, true); if ( provider == null ) { Log.d("SistemaGPS.ativar", "Nenhum provedor encontrado."); } else { Log.d("SistemaGPS.ativar", "Provedor utilizado: " + provider); //lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, TEMPO_DE_ATUALIZACAO, DISTANCIA_DE_ATUALIZACAO , this); lm.requestLocationUpdates(provider, TEMPO_DE_ATUALIZACAO, DISTANCIA_DE_ATUALIZACAO , this); } } public void updateList(Location loc){ Point p = new Point(); p.setLatitude(loc.getLatitude()); p.setLongitude(loc.getLongitude()); pt.add(p); } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "Lat: " + location.getLatitude() + "Long: " + location.getLongitude(), Toast.LENGTH_LONG).show(); updateList(location); } @Override public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } @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 } @Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Auto-generated method stub Toast.makeText(getBaseContext(), "Serviço iniciado", Toast.LENGTH_SHORT).show(); pt = new ArrayList&lt;Point&gt;(); lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); setGPS(); Toast.makeText(getBaseContext(), "GPS setado", Toast.LENGTH_SHORT).show(); return START_STICKY; } @Override public void onDestroy() { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "Serviço parado", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "Lat: " + latitude + "Long: " + longitude, Toast.LENGTH_SHORT).show(); Intent it = new Intent(getApplicationContext(), ShowPoints.class); it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Bundle b = new Bundle(); b.putParcelableArrayList("points", pt); it.putExtras(b); startActivity(it); super.onDestroy(); } @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } </code></pre> <p>}</p>
    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