Android GPS as an Activity
<p>This is working perfectly for me.</p>

<pre><code>public class GPSActivity extends Activity {
LocationManager locmgr = null;
String android_id;
DbAdapter db;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    db = new DbAdapter(getBaseContext());
    db.open();

    android_id = Secure.getString(getBaseContext().getContentResolver(), Secure.ANDROID_ID);
    locmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this.onLocationChange);
    Toast.makeText(getBaseContext(), "Waiting for location..." , Toast.LENGTH_SHORT).show();
}

  LocationListener onLocationChange=new LocationListener() {
        public void onLocationChanged(Location loc) {
            String latlong = "Lat: " + loc.getLatitude() + " Long: " + loc.getLongitude();  
            Toast.makeText(getBaseContext(), latlong, Toast.LENGTH_SHORT).show();
            try{ 
                 db.insertGPSCoordinates(android_id, Double.toString(loc.getLatitude()), Double.toString(loc.getLongitude()));
            }
            catch(Exception e){
            }
        } 
        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

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

    //pauses listener while app is inactive
    @Override
    public void onPause() {
        super.onPause();
        locmgr.removeUpdates(onLocationChange);
    }

    //reactivates listener when app is resumed
    @Override
    public void onResume() {
        super.onResume();
        locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, onLocationChange);
    }
  }
</code></pre>

<p>How do I use this from Broadcastreceiver ? I want to to start collecting co-ordinates when BOOT_COMPLETE.  And keep that running depending on that    <code>locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this.onLocationChange);</code>  setting. I am getting confused how to keep that working periodically.                                          </p>
