Asynctask implements LocationListener : onLocationChanged never called
<p>I make a simple code who allow an user to get his current GPS position when he push some button.
So, i create a MainActivity and an Asynctask class, the Asynctask implements LocationListener but the override onLocationChanged is never call ! (no trace in LogCat..)
Then, I get gps data but he never change when I push the button :/</p>

<p>And if I leave the application, if I force the processus to exit in parameter option Android and I launch again my apps, the gps data keep same. I don't understand that..and why the override method is never called.</p>

<p>Here my only file : </p>

<p>public class MainActivity extends Activity {</p>

<pre><code>    public static Context context;
    public Button push = null;
    public getGPS tache_getGPS = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = getApplication().getApplicationContext();

        push = (Button) findViewById(R.id.button);
        push.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.i("T: onClick", "debut");
                tache_getGPS = new getGPS();
                tache_getGPS.execute();
                Log.i("T: onClick", "fin");
                // TODO Auto-generated method stub
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

class getGPS extends AsyncTask&lt;Void, Integer, Location&gt; implements
        LocationListener {

    final long REFRESH = 5 * 1000;
    private Location location;
    private LocationManager lm;

    protected void onPreExecute() {
        Log.i("T: onPreExcute", "debut");
        Criteria crit = new Criteria();
        crit.setAccuracy(Criteria.ACCURACY_FINE);

        // Configure location manager - I'm using just the network provider in
        // this example
        lm = (LocationManager) MainActivity.context
                .getSystemService(Context.LOCATION_SERVICE);

        String best = lm.getBestProvider(crit, false);
        Log.i("T: onPreExecute", "best : " + best);

        lm.requestLocationUpdates(best, 0, 1, this);
        location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        // nearProgress.setVisibility(View.VISIBLE);
        Log.i("T: onPreExcute", "fin");
    }

    protected Location doInBackground(Void... params) {
        Log.i("T: doInBackground", "debut");

        // Try to use the last known position
        Location lastLocation = lm
                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                /*
        // If it's too old, get a new one by location manager
        if (System.currentTimeMillis() - lastLocation.getTime() &gt; REFRESH) {
            while (location == null)
                try {
                    Thread.sleep(100);
                } catch (Exception ex) {
                }

            return location;
        }
                */
        Log.i("T: doInBackground", "fin");
        return lastLocation;
    }

    protected void onPostExecute(Location location) {
        Log.i("T: onPostExecute", "debut");
        // nearProgress.setVisibility(View.GONE);

        lm = (LocationManager) MainActivity.context
                .getSystemService(Context.LOCATION_SERVICE);
        lm.removeUpdates(this);

        Log.i("T: onPostExecute",
                "Altitude : " + String.valueOf(location.getAltitude()));
        Log.i("T: onPostExecute",
                "Longitude : " + String.valueOf(location.getLongitude()));
        Log.i("T: onPostExecute",
                "Latitude : " + String.valueOf(location.getLatitude()));
        Log.i("T: onPostExecute",
                "Precision(mètre) : " + String.valueOf(location.getAccuracy()));
        Log.i("T: onPostExecute", "fin");

        Toast.makeText(
                MainActivity.context,
                "Altitude : " + String.valueOf(location.getAltitude()) + "\n"
                        + "Longitude : "
                        + String.valueOf(location.getLongitude()) + "\n"
                        + "Latitude : "
                        + String.valueOf(location.getLatitude()) + "\n"
                        + "Precision(mètre) : "
                        + String.valueOf(location.getAccuracy()),
                Toast.LENGTH_SHORT).show();

        return;
    }

    @Override
    public void onLocationChanged(Location newLocation) {
        Log.i("T: onLocationChanged", "debut");
        location = newLocation;
        Log.i("T: onLocationChanged", "fin");
    }

    @Override
    public void onProviderDisabled(String provider) {
        Log.i("T: onProviderDisabled", provider);
    }

    @Override
    public void onProviderEnabled(String provider) {
        Log.i("T: onProviderEnabled", provider);
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        Log.i("T: onStatusChanged", "provider : " + provider);
        Log.i("T: onStatusChanged", "status : " + status);
        Log.i("T: onStatusChanged", "extras : " + extras.toString());
    }

}
</code></pre>

<p>Thanks for help, and sorry for my poor english writing x)</p>

<p>NEW CODE (after advises =) ), without Asinctask</p>

<pre><code>public class MainActivity extends Activity implements LocationListener{

    public static Context context;
    public Button push = null;
    public getGPS tache_getGPS = null;

    private Location location;
    private LocationManager lm;
    final long REFRESH = 5 * 1000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = getApplication().getApplicationContext();

        push = (Button) findViewById(R.id.button);
        push.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.i("T: onClick", "debut");
                location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                Location lastLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                if (System.currentTimeMillis() - lastLocation.getTime() &gt; REFRESH) {
                     while (location == null) 
                         try { Thread.sleep(100); } catch (Exception ex) { }
                     Log.i("FINAL : location", location.toString());
                     Toast.makeText(MainActivity.context, "location : "+location.toString(), Toast.LENGTH_SHORT).show();
                     return;
                }
                Log.i("FINAL : lastlocation", lastLocation.toString());
                Toast.makeText(MainActivity.context, "lastLocation : "+lastLocation.toString(), Toast.LENGTH_SHORT).show();
                Log.i("T: onClick", "fin");
            }
        });
    }

    @Override
    protected void onResume(){
        super.onResume();
        Criteria crit = new Criteria();
        crit.setAccuracy(Criteria.ACCURACY_FINE);
        lm = (LocationManager) MainActivity.context.getSystemService(Context.LOCATION_SERVICE);

        String best = lm.getBestProvider(crit, false);
        Log.i("T: onPreExecute", "best : " + best);

        lm.requestLocationUpdates(best, 1, 1, this);
    }

    @Override
    protected void onPause(){
        super.onPause();
        lm.removeUpdates(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onLocationChanged(Location newLocation) {
        Toast.makeText(context, "onLocationChanged", Toast.LENGTH_SHORT).show();
        Log.i("T: onLocationChanged", "debut");
        location = newLocation;
        Log.i("T: onLocationChanged", "fin");
    }

    @Override
    public void onProviderDisabled(String provider) {
        Log.i("T: onProviderDisabled", provider);
    }

    @Override
    public void onProviderEnabled(String provider) {
        Log.i("T: onProviderEnabled", provider);
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        Log.i("T: onStatusChanged", "provider : " + provider);
        Log.i("T: onStatusChanged", "status : " + status);
        Log.i("T: onStatusChanged", "extras : " + extras.toString());
    }

}
</code></pre>
