3

I know that GoogleApiClient is deprecated and the new class that should be used is GoogleSignInClient, as explained by Paresh Mayani in this answer. However, when I used GoogleApiClient in the back, in my MainActivity I was always calling:

googleApiClient.connect();

In the onStart() and:

googleApiClient.disconnect();

In the onStop().

Is this still required?

Lilian Sorlanski
  • 405
  • 1
  • 3
  • 15

1 Answers1

1

Both GoogleApiClient and GoogleSignInClient are different. Since you are using GoogleSignInClient, it is not necessary to connect/disconnect GoogleApiClient

Also for reference:

GoogleApiClient is used with a variety of static methods. Some of these methods require that GoogleApiClient be connected, some will queue up calls before GoogleApiClient is connected; check the specific API documentation to determine whether you need to be connected.

This is the demonstration of how GoogleAPIClient works internally This is the demonstration of how GoogleAPIClient works internally

Reference link: https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient

As recommended by the Google APIs for Android documentation, please migrate to GoogleApi. Following is the migration link:

Migration Link: https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApi

I hope this helps.

Salman Khakwani
  • 6,684
  • 7
  • 33
  • 58
  • I've read the docs and I still don't understand. So it is still required or not? Thanks – Lilian Sorlanski Aug 21 '19 at 06:24
  • It totally depends on the functions that you are using of the `GoogleApiClient`, if that specific method needs connectivity as a pre-requisite, then you need the `GoogleApiClient` to be in `connected` state. I would suggest that you should keep the `GoogleApiClient` in connected state that way you will be able to use all the methods that needs the `GoogleApiClient` to be either connected or not connected. – Salman Khakwani Aug 21 '19 at 06:27
  • 1
    Voted-up for your answer and comment but I still don't get it. In the past, I was using GoogleApiClient, now there is nothing in my project related to that due the fact that I'm using the `GoogleSignInClient` class. Using only this class, is it still required to maintain some connection or not? Does this practice need to connect/disconnect when the app starts/stops? – Lilian Sorlanski Aug 21 '19 at 06:32
  • Thanks for the up-vote. Yes, it is important to connect and disconnect the `GoogleApiClient ` with respect to the Activity/Fragment's life cycle. Because `GoogleApiClient` is a wrapper that connects your app to the services that are bundled with `Google Play Services` and `Google Sign-in` is one of them. I have also edited the answer, for your connivence. – Salman Khakwani Aug 21 '19 at 06:51
  • I think you don't understand what I mean. I'll try it again. According to your comment, I know't is important to connect and disconnect the `GoogleApiClient`, I used it till yesterday but NOT I'M NOT USING ANYMORE. So let's don't talk about it. Now I'm using **only** the GoogleSignInClient class., is it still required to maintain some connection or not? Does this practice need to connect/disconnect when the app starts/stops with respect to the Activity/Fragment's life-cycle.? – Lilian Sorlanski Aug 21 '19 at 06:58
  • Ok, I got it now. Both `GoogleApiClient` and `GoogleSignInClient` are different. Since you are using `GoogleSignInClient`, it is not necessary to connect/disconnect `GoogleApiClient`. – Salman Khakwani Aug 21 '19 at 07:08
  • 1
    Ok, thank you so much for answering my question, I'm good now. Please update your answer with some relevant informations from the docs so I can accept it. – Lilian Sorlanski Aug 21 '19 at 07:14
  • Sure, I am updating my answer. – Salman Khakwani Aug 21 '19 at 08:15