Wednesday, November 22, 2017

Google Dives Deep Into the New Google Play Services APIs

Version 11.6 of the Google Play services SDK — Google's development kit for the Play Store — is packed to the brim with new features. In an effort to brace folks for the changes, the search giant published an article on migrating to the new APIs earlier this year. And in a new post on the Android Developers blog, it highlighted the many ways in which the SDK tweaks application behavior.

GoogleApi and Task, which replace the GoogleApiClient access pattern in the new Google Play services SDK, were designed to "reduce boilerplate, improve UX, and simplify authentication and authorization," Google Developers Programs Engineer Sam Stern wrote in a blog post. In previous versions of the SDK, GoogleApiClient connected to Google Play's servers only when all of the APIs were available and when the user had signed in, assuming the APIs required it. Over time, Google realized that this model had a number of pitfalls:

  • Any connection failure prevented the use of any of the requested APIs, but using multiple GoogleApiClient objects was unwieldy.

  • The concept of a "connection" was inappropriately overloaded. Connection failures could result from Google Play services authentication issues.

  • The developer had to track the connection state, because making some calls before onConnected was called resulted in a crash.

  • Making a simple API call could mean waiting for two callbacks: One to wait until the GoogleApiClient was connected, and another for the API call itself.

To alleviate a few of the issues that developers ran into, Google Play Services SDK version 11.6.0 introduces updated APIs. "Each API now has a purpose-built client object class that extends GoogleApi," Stern explained. "Unlike with GoogleClientApi there is no performance cost to creating many client objects. Each of these client objects abstracts the connection logic, connections are automatically managed by the SDK in a way that maximizes both speed and efficiency."

Here's a list of them:

  • Auth – updated the Google Sign In and Credentials APIs.

  • Drive – updated the Drive and Drive Resource APIs.

  • Fitness – updated the Ble, Config, Goals, History, Recording, Sensors, and Sessions APIs.

  • Games – updated the Achievements, Events, Games, Games Metadata, Invitations, Leaderboards, Notifications, Player Stats, Players, Realtime Multiplayer, Snapshots, Turn Based Multiplayer, and Videos APIs.

  • Nearby – updated the Connections and Messages APIs.

The APIs join Awareness, Cast, Places, Location, and Wallet, and other APIs that separated from the Google Play connection process in earlier versions of the SDK. With any luck, they'll serve as a more modular, flexible replacement of GoogleApiClient.

That's not all. Here's a few of benefits you can expect from the new Google Play services SDK:

  • No connection logic, calls that require a connection are queued until a connection is available. Connections are pooled when appropriate and torn down when not in use, saving battery and preventing memory leaks.

  • Sign in is completely separated from APIs that consume GoogleSignInAccount which makes it easier to use authenticated APIs throughout your app.

  • Asynchronous API calls use the new Task API rather than PendingResult, which allows for easier management and chaining.

For a more thorough breakdown of the SDK and instructions on how to implement it, head to the source link.


Source: Android Developers Blog



from xda-developers http://ift.tt/2zctnp6
via IFTTT

No comments:

Post a Comment