Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LocationManager locationManager;
- static LocationListener locationListener;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.myactivity);
- // Acquire a reference to the system Location Manager
- locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
- // Define a listener that responds to location updates
- locationListener = new LocationListener() {
- public void onLocationChanged(Location location) {
- // Called when a new location is found by the network location provider.
- if ((location != null) && (location.getAccuracy()<25) ) {
- LoadTask loadtext = new LoadTask();
- loadtext.execute();
- }
- }
- };
- // Register the listener with the Location Manager to receive location updates
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER , 100, 1, locationListener);
- locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER , 100, 1, locationListener);
- }
- @Override
- protected void onStop() {
- super.onStop();
- locationManager.removeUpdates(locationListener);
- locationManager = null;
- }
- ...
- private class LoadTask extends AsyncTask<Void, Void, Void> { ...
Add Comment
Please, Sign In to add comment