Search code examples
androidgoogle-play-servicesgoogle-api-client

Connect with GoogleApiClient though it has already been connected


I am working in an android application where i am using GoogleAPI . In OnCreate() method ,

i connect with the GoogleApiClient . My question is : Suppose , GoogleApiClinet is connected. Now if in another method , i call for the connection with GoogleApiClient again , will it create any problem with the speed & performance of my application ?

Again i am using Geofencing also . suppose , some places are registered with Geofence. I call again the method to register with the same places & it does not create any problem . But my question is , will it create any harm internally or make my application slow ?


Solution

  • No, it will not create any harm with your application. I suggest you to check this Accessing Google APIs documentation for it.

    It is stated here that when you want to make a connection to one of the Google APIs provided in the Google Play services library (such as Google Sign-In, Games, or Drive), you need to create an instance of GoogleApiClient ("Google API Client"). The Google API Client provides a common entry point to all the Google Play services and manages the network connection between the user's device and each Google service.

    Here is the sample code that uses GoogleApiClient with multiple API and scope.

    GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this /* FragmentActivity */,
                          this /* OnConnectionFailedListener */)
        .addApi(Drive.API)
        .addScope(Drive.SCOPE_FILE)
        .build();
    

    You can add multiple APIs and multiple scopes to the same GoogleApiClient by appending additional calls to addApi() and addScope().

    If you want to connect the GoogleApiClient Manually, then this part of documentation can help you with that.