Quit Google Plus api

I just enabled the Google+ button for my app. Everything works great when you log in, share and get information about people. However, I have a feeling that I have one huge flaw in the way I do it, which could prevent the G + from coming out correctly.

I have LoginActivity

where I am instantiating mGoogleApiClient

. As soon as I register the check and update my DB and var with the person information, I will finish()

LoginActivity

and go to mine MainActivity

. Here the user can select an exit.

However, I am afraid that I need the same instance mGoogleApiClient

; but it was destroyed when I finished LoginActivity

. So I changed things up a bit and tried to store it as a static var in another one Activity

I ahve where I use some variables globally - this extends Application

, but it doesn't seem to be written out.

Am I on the right track or do I need to do it differently?

+3


source to share


2 answers


you need to reconnect to the google play service in MainActivity

with all the same permissions you have in LoginActivity

so that you can use this instance to log out



0


source


In your new activity, do the following:



GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(Plus.API)
        .addScope(Plus.SCOPE_PLUS_LOGIN)
        .build();
mGoogleApiClient.connect();
// connect to current session

Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
// clear account
mGoogleApiClient.disconnect();
// disconnect

      

+1


source







All Articles