I have integrated google and facebook sign up using their respective methods. But after successful signing, I want to open different activity and similarly user can go to various different activities. I have used action bar where I am giving an option to sign out from either of the account that the user has logged in. How could I sign out the user when I am in different activity then the main activity. I am getting an exception and I am not able to pass apiclient reference (for google) and session reference (for facebook) to another activity. Please help. Thanks in advance.
Log out on the Facebook mobile app On your smartphone, it's also pretty simple to log out. Tap the icon of three parallel lines. Scroll down to the bottom and tap "Log Out." You'll then be prompted to confirm that you wish you log out.
To sign out of Gmail or Google Apps, click on your email address in the top right of your screen and select Sign out.
Once on the site, click “Security -> Your devices,” then click the three-dot menu icon next to the devices you want to sign out of and click “Sign out.” That's it.
Log out from google:
Just add this on your new activity, where you want your logout-button for google+ to be there :
@Override
protected void onStart() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mGoogleApiClient.connect();
super.onStart();
}
and next you can set setOnClickListener on button:
signout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
// ...
Toast.makeText(getApplicationContext(),"Logged Out",Toast.LENGTH_SHORT).show();
Intent i=new Intent(getApplicationContext(),MainActivity.class);
startActivity(i);
}
});
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With