To stop location updates can be called method 19 Android

To stop location updates can be called method 19

This preview shows page 19 - 24 out of 60 pages.

To stop location updates, can be called removeLocationUpdates()method.19
Background image
Android Receiving Location UpdatesStep 6 - Optional - Save the State of the Activity A change to the device's configuration, such as a change in screen orientation or language, can cause the current activity to be destroyed. The app must therefore store any information it needs to recreate the activity. One way to do this is via an instance state stored in a Bundle object.20
Background image
Android Displaying a Location AddressStep 1 - Get a Geographic LocationThe last known location of the device is a useful starting point for the address lookup feature. The getLastLocation()method, provided by the fused location provider, can be used to find the latest location of the device.To access the fused location provider an instance of the Google Play services API client need to be created.Permission (in Manifest):<uses-permission android:name= "android.permission.ACCESS_FINE_LOCATION"/>21
Background image
Android Displaying a Location AddressStep 2 - Define an Intent Service to Fetch the AddressThe getFromLocation()method provided by the Geocoderclass accepts a latitude and longitude, and returns a list of addresses. The method is synchronous, and may take a long time to do its work, so it shouldn’t be call from the main, user interface (UI) thread of the app.The IntentServiceclass provides a structure for running a task on a background thread. Using this class, can be handled a long-running operation without affecting the UI's responsiveness.FetchAddressIntentServiceclass extends IntentService. This class is address lookup service. The service uses a Geocoderto fetch the address for the location and sends the results to the ResultReceiverin the activity that started the service.22
Background image
Android Displaying a Location AddressStep 3 - Start the Intent ServiceThe intent service runs in the background and is responsible for fetching the address corresponding to a given geographic location. When the service is started, the Android framework instantiates and starts the service if it isn't already running, and creates a process if needed. If the service is already running then it remains running. Because the service extends IntentService, it shuts down automatically when all intents have been processed.Step 4 - Receive the Geocoding ResultsThe intent service has handled the geocoding request, and uses a ResultReceiverto return the results to the activity that made the request. In the activity that makes the request, an AddressResultReceiverthat extends ResultReceivercan be defined to handle the response from FetchAddressIntentService.The result includes a numeric result code (resultCode) as well as a message containing the result data (resultData).
Background image
Image of page 24

You've reached the end of your free preview.

Want to read all 60 pages?

  • '19
  • Geographic coordinate system, Google Maps

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture