The recent release of Google Play Services 4.2 brought with it some exciting additions like the official Cast API and significantly improved support for Google Drive. One of the lesser publicized additions is the official launch of GoogleApiClient, a new component intended to simplify setting up and managing connections to Google's assorted API endpoints. Additionally, there is now support for queuing up read-only queries and a choice of executing calls synchronously or asynchronously.

[EMBED_YT]https://www.youtube.com/watch?v=6-F8TjLMQYw

[/EMBED_YT]

A chief advantage of the new GoogleApiClient object is that it cuts out the need for multiple sets of callback methods and client objects for each distinct service (e.g. Drive, Games, Google+, etc). This will also make it easier to consolidate authorization requests for the user into a single prompt.

The GoogleApiClient isn't exactly brand new; it has been present in Play Services for some time, at least since early December. Like the APIs for Drive and Cast, the new client API model went through a testing phase as a "developer preview" before being deemed an officially supported part of the SDK.

Besides the new client API model, GMS also brought a couple of other great improvements. The SDK now supports queuing up read-only API calls when the connection is not yet active. This feature allows developers to make a request for data that will wait to be completed once a connection is established. The other major addition is support for asynchronous and synchronous API calls to Google services. When a method call is made, it returns a PendingResult object. To wait for the result before continuing with execution, simply add .await() to the end of the call and the thread will block until it completes.

With official support for GoogleApiClient, the older client objects belonging to each service have been officially deprecated. There is no specific date for the removal of the old APIs, but they will remain operational for a while, giving developers plenty of time to update their code. In many cases, the changes should only require modifications to a few lines of code and consolidating callback methods. For more details and samples, check out the blog post and detailed getting started documentation for Accessing Google Play Services APIs.

[Correction] Apps that rely on the older API will continue to work just fine, but they will be limited to older versions of the library. To use newer versions of the library will require switching over to GoogleApiClient. - Thanks, Shaftway!

Source: Android Developer Blog