Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sign out from google and facebook in android application

Tags:

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.

like image 794
Jarvis Avatar asked Jan 13 '15 11:01

Jarvis


People also ask

How do I sign out of Facebook app on Android?

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.

How do you log out of Google on the app?

To sign out of Gmail or Google Apps, click on your email address in the top right of your screen and select Sign out.

How do I sign out of Android?

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.


1 Answers

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);
                  }
              });
  }
});
like image 100
sommesh Avatar answered Sep 26 '22 03:09

sommesh