Return to Video

Describe Workflow

  • 0:01 - 0:04
    When building an app that uses
    location services like this,
  • 0:04 - 0:07
    there are a number of events that
    happen in the app lifecycle,
  • 0:07 - 0:11
    in addition to the usual
    activity lifecycle events.
  • 0:11 - 0:15
    Let's take a look at the entire
    set of events, one by one, and
  • 0:15 - 0:17
    specify what we need to do in each.
  • 0:17 - 0:20
    First of course, is the OnCreate method.
  • 0:20 - 0:22
    We've implemented this already.
  • 0:22 - 0:25
    This is called when our
    activity is created.
  • 0:25 - 0:28
    In this we set up the GoogleApiClient.
  • 0:30 - 0:33
    And we tell it to use
    location services and
  • 0:33 - 0:37
    the location of the call backs to call
    when stuff happens on the client.
  • 0:38 - 0:41
    Once OnCreate has done its thing
    the app will start running.
  • 0:43 - 0:47
    And because we're using asynchronous
    callbacks on the GoogleApiClient
  • 0:47 - 0:51
    more functions are going to fire
    while the client is running.
  • 0:51 - 0:57
    So immediately after OnCreate Android
    calls the OnStart activity.
  • 0:57 - 0:59
    And in this we will tell
    the GoogleApiClient
  • 1:00 - 1:04
    again to start connecting
    to location services.
  • 1:05 - 1:09
    Depending on the relationship
    between the client and
  • 1:09 - 1:12
    the location services,
    one of three things will happen.
  • 1:13 - 1:17
    If it connects successfully
    the OnConnected callback will fire.
  • 1:19 - 1:20
    We'll look at this in a moment.
  • 1:21 - 1:24
    If it fails,
    the OnConnectionFailed will fire.
  • 1:26 - 1:28
    If it was previously connected, but
  • 1:28 - 1:32
    something has gone wrong with
    the connection causing it to suspend,
  • 1:32 - 1:34
    then the OnConnectionSuspended
    will fire.
  • 1:36 - 1:41
    You need to implement all three of these
    functions or your app won't compile.
  • 1:41 - 1:45
    So be sure at the very least to put a
    logging line in the ones that you don't
  • 1:45 - 1:49
    want to write detailed code for yet,
    for example the OnConnectionFailed and
  • 1:49 - 1:51
    the OnConnectionSuspended.
  • 1:51 - 1:53
    Now let's look at OnConnected.
  • 1:53 - 1:58
    In this method, we'll create
    a new LocationRequest object.
  • 1:58 - 2:01
    We'll set its priority,
    we'll set its interval, and
  • 2:01 - 2:06
    then we'll start requesting
    updates from Location Services.
  • 2:06 - 2:08
    We'll see what that code
    looks like in a moment.
  • 2:09 - 2:13
    Now when the Location Services see
    a new location for the device,
  • 2:13 - 2:18
    they will then give a callback
    to OnLocationChanged, and
  • 2:18 - 2:20
    this will give you a location object.
  • 2:21 - 2:25
    This object, you can parse with
    details about the location,
  • 2:25 - 2:26
    such as the latitude and longitude.
Title:
Describe Workflow
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
UD876-1 - Google Play Services - Location & Contex
Duration:
02:28

English subtitles

Revisions Compare revisions