On my Android app I have a Google Plus sign-in button in my MainActivity. I use these lines in my onCLick() method:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, Plus.PlusOptions.builder().build())
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
mGoogleApiClient.connect();
And the first time I press the button a sign-in window comes up. I log in successfully with my google account into HomeActivity, and then successfully logout, using this 2 lines:
Plus.AccountApi.clearDefaultAccount(AppController.getInstance().getmGoogleApiClient());
mGoogleApiClient.disconnect();
(I tried to put mGoogleApiClient.connect();
as a 3rd line.. it didn't change anything)
So then I return to MainActivity, but when I press the sign-in Button again, it automatically signs me in back to HomeActivity, without popping up the sign-in window like the first time... although I alledgedly signed-out...
Does someone know what else should I add to my code? Or perhaps there is a way to manually show that sign-in window? What makes it pop the first time?
Thank you very much!
Add this part of code in your onCreate method:
GoogleSignInOptions googleSignInOptions =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, connectionResult -> Toast.makeText(
this, "Connection failed",
Toast.LENGTH_SHORT).show())
.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build();
And then simply add this line when signing out
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.clearDefaultAccountAndReconnect();
}
You need to add the following code at Log out, so it will clear all user data from your app, and after re-login you will get popping up the sign-in window like the first time.
public void signOutFromGplus() {
if (mGoogleApiClient.isConnected()) {
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient);
mGoogleApiClient.disconnect();
mGoogleApiClient.connect();
}
}
You have to add these lines on logout click code block
Firebase.auth.signOut()
mAuth?.signOut()
mGoogleSignInClient?.signOut()
this will resolve your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.