Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple instances of Google API Client?

I have activity A that instantiates GoogleApiClient, connects and starts processing in AsyncTask that may take seconds or minutes.

Meanwhile, user triggers activity B that instantiates it's own GoogleApiClient with a connection.

The question is: Can an app have multiple instances of GoogleApiClient connected and working simultaneously, or should I keep an app singleton with my own semaphores?

like image 871
seanpj Avatar asked Mar 31 '14 16:03

seanpj


People also ask

Is GoogleApiClient deprecated?

Yeah GoogleApiClient has been deprecated. Particularly for the authentication api, you now need to use GoogleSignInClient .

What is Google API client?

Figure 1: An illustration showing how the Google API Client provides an interface for connecting and making calls to any of the available Google Play services such as Google Play Games and Google Drive. To get started, you must first install the Google Play services library (revision 15 or higher) for your Android SDK.

What is API client libraries?

Client-Library is an applications programming interface (API) for use in writing client applications. Client-Library provides generic building blocks for constructing distributed client applications, including non-database applications.

What is Google API Python client?

The Google API Client Library for Python is designed for Python client-application developers. It offers simple, flexible access to many Google APIs.


2 Answers

It's perfectly fine to keep as many GoogleApiClients as you want around, and there are often good reasons for doing so (separation of fragments, different accounts, etc.). It's also not particularly inefficient. The cost of two clients is less than 1% higher than the cost of one client.

It can be confusing if all of them are trying to resolve errors, so it's probably a good idea to make the Fragment clients all ignore connection failures, and have an Activity or Application level client responsible for resolving issues.

like image 114
Hounshell Avatar answered Oct 19 '22 06:10

Hounshell


Its possible to have multiple connected GoogleApiClients, just possibly inefficient. You do need to be careful using GoogleApiClient with AsyncTasks that it isn't disconnected if the activity goes away.

Consider managing the GoogleApliClient within a retained fragment. See http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html

like image 23
Cheryl Simon Avatar answered Oct 19 '22 04:10

Cheryl Simon