Search code examples
google-drive-apigoogle-drive-android-api

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?


Solution

  • 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