Guest User

Untitled

a guest
Jan 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. LocationManager locationManager;
  2. static LocationListener locationListener;
  3.  
  4. public void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.myactivity);
  7.  
  8. // Acquire a reference to the system Location Manager
  9. locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  10.  
  11. // Define a listener that responds to location updates
  12. locationListener = new LocationListener() {
  13. public void onLocationChanged(Location location) {
  14.  
  15. // Called when a new location is found by the network location provider.
  16. if ((location != null) && (location.getAccuracy()<25) ) {
  17. LoadTask loadtext = new LoadTask();
  18. loadtext.execute();
  19. }
  20. }
  21. };
  22.  
  23. // Register the listener with the Location Manager to receive location updates
  24. locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER , 100, 1, locationListener);
  25. locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER , 100, 1, locationListener);
  26. }
  27.  
  28. @Override
  29. protected void onStop() {
  30. super.onStop();
  31. locationManager.removeUpdates(locationListener);
  32. locationManager = null;
  33. }
  34.  
  35. ...
  36.  
  37. private class LoadTask extends AsyncTask<Void, Void, Void> { ...
Add Comment
Please, Sign In to add comment