Google Firebase sign out and forget user in Android app










16















When I call mFirebaseAuth.signOut() or mFirebaseUser.delete() my FirebaseAuth.AuthStateListener() works correct and returns null as FirebaseUser instance in onAuthStateChanged, I refresh UI and show "Sign in with Google" button.



But when I want to log in again, I don't see the pop-up with users (I have 2 users on my device, attached the image). The app shows this pop-up only in first sign in, after that it uses the same user. If I clear app's data on the settings screen I will be able to see this pop-up again.



My question is how to show this pop-up after every sign out.



enter image description here



I run this code when press Sign In button:



GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, FirebaseActivity.REQUEST_SIGN_IN);


In onActivityResult(), I get an instance of GoogleSignInResult so everything I need happens after I call startActivityForResult().










share|improve this question
























  • Code or it didn't happen. Let's see your logic for showing the popup.

    – Chad Bingham
    Aug 1 '16 at 20:20











  • A quick guess: calling signOut() signs the user our of Firebase Authentication. It does not sign the user out of the underlying social provider (e.g. Facebook, Google). So next time your start the sign-in flow for that provider, it will be picked up immediately by your code (or the library that you used). But it'll be easier indeed to say what's going if you show the minimal code that reproduces the problem.

    – Frank van Puffelen
    Aug 1 '16 at 20:31











  • You might get some clues by comparing your code with the Firebase Auth Quickstart project. When I run it using Google Signin, the account picker dialog is presented every time. Don't know if that is true for Twitter, Facebook, etc.

    – Bob Snyder
    Aug 1 '16 at 20:46












  • @FrankvanPuffelen added the code

    – GrafOrlov
    Aug 1 '16 at 20:46











  • @qbix google authentication

    – GrafOrlov
    Aug 1 '16 at 20:48















16















When I call mFirebaseAuth.signOut() or mFirebaseUser.delete() my FirebaseAuth.AuthStateListener() works correct and returns null as FirebaseUser instance in onAuthStateChanged, I refresh UI and show "Sign in with Google" button.



But when I want to log in again, I don't see the pop-up with users (I have 2 users on my device, attached the image). The app shows this pop-up only in first sign in, after that it uses the same user. If I clear app's data on the settings screen I will be able to see this pop-up again.



My question is how to show this pop-up after every sign out.



enter image description here



I run this code when press Sign In button:



GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, FirebaseActivity.REQUEST_SIGN_IN);


In onActivityResult(), I get an instance of GoogleSignInResult so everything I need happens after I call startActivityForResult().










share|improve this question
























  • Code or it didn't happen. Let's see your logic for showing the popup.

    – Chad Bingham
    Aug 1 '16 at 20:20











  • A quick guess: calling signOut() signs the user our of Firebase Authentication. It does not sign the user out of the underlying social provider (e.g. Facebook, Google). So next time your start the sign-in flow for that provider, it will be picked up immediately by your code (or the library that you used). But it'll be easier indeed to say what's going if you show the minimal code that reproduces the problem.

    – Frank van Puffelen
    Aug 1 '16 at 20:31











  • You might get some clues by comparing your code with the Firebase Auth Quickstart project. When I run it using Google Signin, the account picker dialog is presented every time. Don't know if that is true for Twitter, Facebook, etc.

    – Bob Snyder
    Aug 1 '16 at 20:46












  • @FrankvanPuffelen added the code

    – GrafOrlov
    Aug 1 '16 at 20:46











  • @qbix google authentication

    – GrafOrlov
    Aug 1 '16 at 20:48













16












16








16


6






When I call mFirebaseAuth.signOut() or mFirebaseUser.delete() my FirebaseAuth.AuthStateListener() works correct and returns null as FirebaseUser instance in onAuthStateChanged, I refresh UI and show "Sign in with Google" button.



But when I want to log in again, I don't see the pop-up with users (I have 2 users on my device, attached the image). The app shows this pop-up only in first sign in, after that it uses the same user. If I clear app's data on the settings screen I will be able to see this pop-up again.



My question is how to show this pop-up after every sign out.



enter image description here



I run this code when press Sign In button:



GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, FirebaseActivity.REQUEST_SIGN_IN);


In onActivityResult(), I get an instance of GoogleSignInResult so everything I need happens after I call startActivityForResult().










share|improve this question
















When I call mFirebaseAuth.signOut() or mFirebaseUser.delete() my FirebaseAuth.AuthStateListener() works correct and returns null as FirebaseUser instance in onAuthStateChanged, I refresh UI and show "Sign in with Google" button.



But when I want to log in again, I don't see the pop-up with users (I have 2 users on my device, attached the image). The app shows this pop-up only in first sign in, after that it uses the same user. If I clear app's data on the settings screen I will be able to see this pop-up again.



My question is how to show this pop-up after every sign out.



enter image description here



I run this code when press Sign In button:



GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, FirebaseActivity.REQUEST_SIGN_IN);


In onActivityResult(), I get an instance of GoogleSignInResult so everything I need happens after I call startActivityForResult().







android firebase google-play-services firebase-authentication






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 22 '18 at 9:46









Grimthorr

4,42442235




4,42442235










asked Aug 1 '16 at 19:59









GrafOrlovGrafOrlov

4172422




4172422












  • Code or it didn't happen. Let's see your logic for showing the popup.

    – Chad Bingham
    Aug 1 '16 at 20:20











  • A quick guess: calling signOut() signs the user our of Firebase Authentication. It does not sign the user out of the underlying social provider (e.g. Facebook, Google). So next time your start the sign-in flow for that provider, it will be picked up immediately by your code (or the library that you used). But it'll be easier indeed to say what's going if you show the minimal code that reproduces the problem.

    – Frank van Puffelen
    Aug 1 '16 at 20:31











  • You might get some clues by comparing your code with the Firebase Auth Quickstart project. When I run it using Google Signin, the account picker dialog is presented every time. Don't know if that is true for Twitter, Facebook, etc.

    – Bob Snyder
    Aug 1 '16 at 20:46












  • @FrankvanPuffelen added the code

    – GrafOrlov
    Aug 1 '16 at 20:46











  • @qbix google authentication

    – GrafOrlov
    Aug 1 '16 at 20:48

















  • Code or it didn't happen. Let's see your logic for showing the popup.

    – Chad Bingham
    Aug 1 '16 at 20:20











  • A quick guess: calling signOut() signs the user our of Firebase Authentication. It does not sign the user out of the underlying social provider (e.g. Facebook, Google). So next time your start the sign-in flow for that provider, it will be picked up immediately by your code (or the library that you used). But it'll be easier indeed to say what's going if you show the minimal code that reproduces the problem.

    – Frank van Puffelen
    Aug 1 '16 at 20:31











  • You might get some clues by comparing your code with the Firebase Auth Quickstart project. When I run it using Google Signin, the account picker dialog is presented every time. Don't know if that is true for Twitter, Facebook, etc.

    – Bob Snyder
    Aug 1 '16 at 20:46












  • @FrankvanPuffelen added the code

    – GrafOrlov
    Aug 1 '16 at 20:46











  • @qbix google authentication

    – GrafOrlov
    Aug 1 '16 at 20:48
















Code or it didn't happen. Let's see your logic for showing the popup.

– Chad Bingham
Aug 1 '16 at 20:20





Code or it didn't happen. Let's see your logic for showing the popup.

– Chad Bingham
Aug 1 '16 at 20:20













A quick guess: calling signOut() signs the user our of Firebase Authentication. It does not sign the user out of the underlying social provider (e.g. Facebook, Google). So next time your start the sign-in flow for that provider, it will be picked up immediately by your code (or the library that you used). But it'll be easier indeed to say what's going if you show the minimal code that reproduces the problem.

– Frank van Puffelen
Aug 1 '16 at 20:31





A quick guess: calling signOut() signs the user our of Firebase Authentication. It does not sign the user out of the underlying social provider (e.g. Facebook, Google). So next time your start the sign-in flow for that provider, it will be picked up immediately by your code (or the library that you used). But it'll be easier indeed to say what's going if you show the minimal code that reproduces the problem.

– Frank van Puffelen
Aug 1 '16 at 20:31













You might get some clues by comparing your code with the Firebase Auth Quickstart project. When I run it using Google Signin, the account picker dialog is presented every time. Don't know if that is true for Twitter, Facebook, etc.

– Bob Snyder
Aug 1 '16 at 20:46






You might get some clues by comparing your code with the Firebase Auth Quickstart project. When I run it using Google Signin, the account picker dialog is presented every time. Don't know if that is true for Twitter, Facebook, etc.

– Bob Snyder
Aug 1 '16 at 20:46














@FrankvanPuffelen added the code

– GrafOrlov
Aug 1 '16 at 20:46





@FrankvanPuffelen added the code

– GrafOrlov
Aug 1 '16 at 20:46













@qbix google authentication

– GrafOrlov
Aug 1 '16 at 20:48





@qbix google authentication

– GrafOrlov
Aug 1 '16 at 20:48












6 Answers
6






active

oldest

votes


















31














In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling GoogleSignInClient.signOut() when you sign-out?



private void signOut() 
// Firebase sign out
mAuth.signOut();

// Google sign out
mGoogleSignInClient.signOut().addOnCompleteListener(this,
new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
updateUI(null);

);






share|improve this answer

























  • No, i didn't call Auth.GoogleSignInApi.signOut() . Thanks a lot, it works now.

    – GrafOrlov
    Aug 1 '16 at 21:00












  • Good find @qbix! I forgot that part of the quickstart code.

    – Frank van Puffelen
    Aug 1 '16 at 23:17











  • Credit really goes to you @FrankvanPuffelen. Your earlier comment put me on the trail.

    – Bob Snyder
    Aug 1 '16 at 23:24






  • 4





    How do I get mGoogleApiClient? And what does updateUI do? How do I do this with Facebook? I have logout in a separate class. Thanks

    – Ab_
    Sep 9 '16 at 17:39












  • @AbAppletic: Look in the Quickstart sample code linked in the answer.

    – Bob Snyder
    Sep 9 '16 at 17:42


















6














Another option is to use the FirebaseUI library. It simplifies sign in and sign out operations in a sense that it will do all the heavy lifting for you.



Kotlin



AuthUI.getInstance().signOut(this).addOnCompleteListener 
// do something here



Java



AuthUI.getInstance()
.signOut(ActivityMainOld.this)
.addOnCompleteListener(new OnCompleteListener<Void>()

@Override
public void onComplete(@NonNull Task<Void> task)

// do something here


);


Hope this helps






share|improve this answer























  • Clean elegant solution .. self-contained, doesn't require involving GoogleApiClient reference. Nice, thanks!

    – Gene Bo
    Oct 29 '18 at 1:25


















3














For anyone else who wants this result (as in getting the google account options back) on a different activity.



public static void signOut() 
// Firebase sign out
mAuth.signOut();

// Google sign out
Auth.GoogleSignInApi.signOut(mGoogleApiClient);



Add this on the sign in page, and before you pass to the next activity, just call SignOut().



// everything ok... 
signOut();
startActivity(new Intent(SignIn.this,NextOne.class));


and then, in your other class you can call



FirebaseAuth.getInstance().signOut();
startActivity(new Intent(NextClass.this, SignIn.class));


It's easy, and it will work. Cheers!






share|improve this answer

























  • it works...thanks @Alex Barbu

    – vijay chhalotre
    Jul 20 '17 at 10:50


















2














You can also define something like this:



private void signOut() 
mAuth.signOut();
mGoogleSignInClient.signOut().addOnCompleteListener(this,
new OnCompleteListener<Void>()
@Override
public void onComplete(@NonNull Task<Void> task)
Intent intent = new Intent(YourActivity.this, NextActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

);






share|improve this answer






























    0














    private void sendToLogin() //funtion
    GoogleSignInClient mGoogleSignInClient ;
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestIdToken(getString(R.string.default_web_client_id))
    .requestEmail()
    .build();
    mGoogleSignInClient = GoogleSignIn.getClient(getBaseContext(), gso);
    mGoogleSignInClient.signOut().addOnCompleteListener(/*CURRENT CLASS */.this,
    new OnCompleteListener<Void>() //signout Google
    @Override
    public void onComplete(@NonNull Task<Void> task)
    FirebaseAuth.getInstance().signOut(); //signout firebase
    Intent setupIntent = new Intent(getBaseContext(), /*To ur activity calss*/);
    Toast.makeText(getBaseContext(), "Logged Out", Toast.LENGTH_LONG).show(); //if u want to show some text
    setupIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(setupIntent);
    finish();

    );



    this code is written to work as copy past just read COMMENTS in code to customize it to ur needs, i prefer to send user to login






    share|improve this answer
































      0














      I did mGoogleSignInClient.signOut()
      this is working as expected.






      share|improve this answer






















        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "1"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38707133%2fgoogle-firebase-sign-out-and-forget-user-in-android-app%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        31














        In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling GoogleSignInClient.signOut() when you sign-out?



        private void signOut() 
        // Firebase sign out
        mAuth.signOut();

        // Google sign out
        mGoogleSignInClient.signOut().addOnCompleteListener(this,
        new OnCompleteListener<Void>()
        @Override
        public void onComplete(@NonNull Task<Void> task)
        updateUI(null);

        );






        share|improve this answer

























        • No, i didn't call Auth.GoogleSignInApi.signOut() . Thanks a lot, it works now.

          – GrafOrlov
          Aug 1 '16 at 21:00












        • Good find @qbix! I forgot that part of the quickstart code.

          – Frank van Puffelen
          Aug 1 '16 at 23:17











        • Credit really goes to you @FrankvanPuffelen. Your earlier comment put me on the trail.

          – Bob Snyder
          Aug 1 '16 at 23:24






        • 4





          How do I get mGoogleApiClient? And what does updateUI do? How do I do this with Facebook? I have logout in a separate class. Thanks

          – Ab_
          Sep 9 '16 at 17:39












        • @AbAppletic: Look in the Quickstart sample code linked in the answer.

          – Bob Snyder
          Sep 9 '16 at 17:42















        31














        In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling GoogleSignInClient.signOut() when you sign-out?



        private void signOut() 
        // Firebase sign out
        mAuth.signOut();

        // Google sign out
        mGoogleSignInClient.signOut().addOnCompleteListener(this,
        new OnCompleteListener<Void>()
        @Override
        public void onComplete(@NonNull Task<Void> task)
        updateUI(null);

        );






        share|improve this answer

























        • No, i didn't call Auth.GoogleSignInApi.signOut() . Thanks a lot, it works now.

          – GrafOrlov
          Aug 1 '16 at 21:00












        • Good find @qbix! I forgot that part of the quickstart code.

          – Frank van Puffelen
          Aug 1 '16 at 23:17











        • Credit really goes to you @FrankvanPuffelen. Your earlier comment put me on the trail.

          – Bob Snyder
          Aug 1 '16 at 23:24






        • 4





          How do I get mGoogleApiClient? And what does updateUI do? How do I do this with Facebook? I have logout in a separate class. Thanks

          – Ab_
          Sep 9 '16 at 17:39












        • @AbAppletic: Look in the Quickstart sample code linked in the answer.

          – Bob Snyder
          Sep 9 '16 at 17:42













        31












        31








        31







        In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling GoogleSignInClient.signOut() when you sign-out?



        private void signOut() 
        // Firebase sign out
        mAuth.signOut();

        // Google sign out
        mGoogleSignInClient.signOut().addOnCompleteListener(this,
        new OnCompleteListener<Void>()
        @Override
        public void onComplete(@NonNull Task<Void> task)
        updateUI(null);

        );






        share|improve this answer















        In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling GoogleSignInClient.signOut() when you sign-out?



        private void signOut() 
        // Firebase sign out
        mAuth.signOut();

        // Google sign out
        mGoogleSignInClient.signOut().addOnCompleteListener(this,
        new OnCompleteListener<Void>()
        @Override
        public void onComplete(@NonNull Task<Void> task)
        updateUI(null);

        );







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 '18 at 22:14

























        answered Aug 1 '16 at 20:55









        Bob SnyderBob Snyder

        26.3k458115




        26.3k458115












        • No, i didn't call Auth.GoogleSignInApi.signOut() . Thanks a lot, it works now.

          – GrafOrlov
          Aug 1 '16 at 21:00












        • Good find @qbix! I forgot that part of the quickstart code.

          – Frank van Puffelen
          Aug 1 '16 at 23:17











        • Credit really goes to you @FrankvanPuffelen. Your earlier comment put me on the trail.

          – Bob Snyder
          Aug 1 '16 at 23:24






        • 4





          How do I get mGoogleApiClient? And what does updateUI do? How do I do this with Facebook? I have logout in a separate class. Thanks

          – Ab_
          Sep 9 '16 at 17:39












        • @AbAppletic: Look in the Quickstart sample code linked in the answer.

          – Bob Snyder
          Sep 9 '16 at 17:42

















        • No, i didn't call Auth.GoogleSignInApi.signOut() . Thanks a lot, it works now.

          – GrafOrlov
          Aug 1 '16 at 21:00












        • Good find @qbix! I forgot that part of the quickstart code.

          – Frank van Puffelen
          Aug 1 '16 at 23:17











        • Credit really goes to you @FrankvanPuffelen. Your earlier comment put me on the trail.

          – Bob Snyder
          Aug 1 '16 at 23:24






        • 4





          How do I get mGoogleApiClient? And what does updateUI do? How do I do this with Facebook? I have logout in a separate class. Thanks

          – Ab_
          Sep 9 '16 at 17:39












        • @AbAppletic: Look in the Quickstart sample code linked in the answer.

          – Bob Snyder
          Sep 9 '16 at 17:42
















        No, i didn't call Auth.GoogleSignInApi.signOut() . Thanks a lot, it works now.

        – GrafOrlov
        Aug 1 '16 at 21:00






        No, i didn't call Auth.GoogleSignInApi.signOut() . Thanks a lot, it works now.

        – GrafOrlov
        Aug 1 '16 at 21:00














        Good find @qbix! I forgot that part of the quickstart code.

        – Frank van Puffelen
        Aug 1 '16 at 23:17





        Good find @qbix! I forgot that part of the quickstart code.

        – Frank van Puffelen
        Aug 1 '16 at 23:17













        Credit really goes to you @FrankvanPuffelen. Your earlier comment put me on the trail.

        – Bob Snyder
        Aug 1 '16 at 23:24





        Credit really goes to you @FrankvanPuffelen. Your earlier comment put me on the trail.

        – Bob Snyder
        Aug 1 '16 at 23:24




        4




        4





        How do I get mGoogleApiClient? And what does updateUI do? How do I do this with Facebook? I have logout in a separate class. Thanks

        – Ab_
        Sep 9 '16 at 17:39






        How do I get mGoogleApiClient? And what does updateUI do? How do I do this with Facebook? I have logout in a separate class. Thanks

        – Ab_
        Sep 9 '16 at 17:39














        @AbAppletic: Look in the Quickstart sample code linked in the answer.

        – Bob Snyder
        Sep 9 '16 at 17:42





        @AbAppletic: Look in the Quickstart sample code linked in the answer.

        – Bob Snyder
        Sep 9 '16 at 17:42













        6














        Another option is to use the FirebaseUI library. It simplifies sign in and sign out operations in a sense that it will do all the heavy lifting for you.



        Kotlin



        AuthUI.getInstance().signOut(this).addOnCompleteListener 
        // do something here



        Java



        AuthUI.getInstance()
        .signOut(ActivityMainOld.this)
        .addOnCompleteListener(new OnCompleteListener<Void>()

        @Override
        public void onComplete(@NonNull Task<Void> task)

        // do something here


        );


        Hope this helps






        share|improve this answer























        • Clean elegant solution .. self-contained, doesn't require involving GoogleApiClient reference. Nice, thanks!

          – Gene Bo
          Oct 29 '18 at 1:25















        6














        Another option is to use the FirebaseUI library. It simplifies sign in and sign out operations in a sense that it will do all the heavy lifting for you.



        Kotlin



        AuthUI.getInstance().signOut(this).addOnCompleteListener 
        // do something here



        Java



        AuthUI.getInstance()
        .signOut(ActivityMainOld.this)
        .addOnCompleteListener(new OnCompleteListener<Void>()

        @Override
        public void onComplete(@NonNull Task<Void> task)

        // do something here


        );


        Hope this helps






        share|improve this answer























        • Clean elegant solution .. self-contained, doesn't require involving GoogleApiClient reference. Nice, thanks!

          – Gene Bo
          Oct 29 '18 at 1:25













        6












        6








        6







        Another option is to use the FirebaseUI library. It simplifies sign in and sign out operations in a sense that it will do all the heavy lifting for you.



        Kotlin



        AuthUI.getInstance().signOut(this).addOnCompleteListener 
        // do something here



        Java



        AuthUI.getInstance()
        .signOut(ActivityMainOld.this)
        .addOnCompleteListener(new OnCompleteListener<Void>()

        @Override
        public void onComplete(@NonNull Task<Void> task)

        // do something here


        );


        Hope this helps






        share|improve this answer













        Another option is to use the FirebaseUI library. It simplifies sign in and sign out operations in a sense that it will do all the heavy lifting for you.



        Kotlin



        AuthUI.getInstance().signOut(this).addOnCompleteListener 
        // do something here



        Java



        AuthUI.getInstance()
        .signOut(ActivityMainOld.this)
        .addOnCompleteListener(new OnCompleteListener<Void>()

        @Override
        public void onComplete(@NonNull Task<Void> task)

        // do something here


        );


        Hope this helps







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 26 '17 at 12:31









        ZooSZooS

        408614




        408614












        • Clean elegant solution .. self-contained, doesn't require involving GoogleApiClient reference. Nice, thanks!

          – Gene Bo
          Oct 29 '18 at 1:25

















        • Clean elegant solution .. self-contained, doesn't require involving GoogleApiClient reference. Nice, thanks!

          – Gene Bo
          Oct 29 '18 at 1:25
















        Clean elegant solution .. self-contained, doesn't require involving GoogleApiClient reference. Nice, thanks!

        – Gene Bo
        Oct 29 '18 at 1:25





        Clean elegant solution .. self-contained, doesn't require involving GoogleApiClient reference. Nice, thanks!

        – Gene Bo
        Oct 29 '18 at 1:25











        3














        For anyone else who wants this result (as in getting the google account options back) on a different activity.



        public static void signOut() 
        // Firebase sign out
        mAuth.signOut();

        // Google sign out
        Auth.GoogleSignInApi.signOut(mGoogleApiClient);



        Add this on the sign in page, and before you pass to the next activity, just call SignOut().



        // everything ok... 
        signOut();
        startActivity(new Intent(SignIn.this,NextOne.class));


        and then, in your other class you can call



        FirebaseAuth.getInstance().signOut();
        startActivity(new Intent(NextClass.this, SignIn.class));


        It's easy, and it will work. Cheers!






        share|improve this answer

























        • it works...thanks @Alex Barbu

          – vijay chhalotre
          Jul 20 '17 at 10:50















        3














        For anyone else who wants this result (as in getting the google account options back) on a different activity.



        public static void signOut() 
        // Firebase sign out
        mAuth.signOut();

        // Google sign out
        Auth.GoogleSignInApi.signOut(mGoogleApiClient);



        Add this on the sign in page, and before you pass to the next activity, just call SignOut().



        // everything ok... 
        signOut();
        startActivity(new Intent(SignIn.this,NextOne.class));


        and then, in your other class you can call



        FirebaseAuth.getInstance().signOut();
        startActivity(new Intent(NextClass.this, SignIn.class));


        It's easy, and it will work. Cheers!






        share|improve this answer

























        • it works...thanks @Alex Barbu

          – vijay chhalotre
          Jul 20 '17 at 10:50













        3












        3








        3







        For anyone else who wants this result (as in getting the google account options back) on a different activity.



        public static void signOut() 
        // Firebase sign out
        mAuth.signOut();

        // Google sign out
        Auth.GoogleSignInApi.signOut(mGoogleApiClient);



        Add this on the sign in page, and before you pass to the next activity, just call SignOut().



        // everything ok... 
        signOut();
        startActivity(new Intent(SignIn.this,NextOne.class));


        and then, in your other class you can call



        FirebaseAuth.getInstance().signOut();
        startActivity(new Intent(NextClass.this, SignIn.class));


        It's easy, and it will work. Cheers!






        share|improve this answer















        For anyone else who wants this result (as in getting the google account options back) on a different activity.



        public static void signOut() 
        // Firebase sign out
        mAuth.signOut();

        // Google sign out
        Auth.GoogleSignInApi.signOut(mGoogleApiClient);



        Add this on the sign in page, and before you pass to the next activity, just call SignOut().



        // everything ok... 
        signOut();
        startActivity(new Intent(SignIn.this,NextOne.class));


        and then, in your other class you can call



        FirebaseAuth.getInstance().signOut();
        startActivity(new Intent(NextClass.this, SignIn.class));


        It's easy, and it will work. Cheers!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 22 '17 at 16:33









        Manfred Radlwimmer

        10.4k123550




        10.4k123550










        answered May 22 '17 at 16:13









        Alex BarbuAlex Barbu

        312




        312












        • it works...thanks @Alex Barbu

          – vijay chhalotre
          Jul 20 '17 at 10:50

















        • it works...thanks @Alex Barbu

          – vijay chhalotre
          Jul 20 '17 at 10:50
















        it works...thanks @Alex Barbu

        – vijay chhalotre
        Jul 20 '17 at 10:50





        it works...thanks @Alex Barbu

        – vijay chhalotre
        Jul 20 '17 at 10:50











        2














        You can also define something like this:



        private void signOut() 
        mAuth.signOut();
        mGoogleSignInClient.signOut().addOnCompleteListener(this,
        new OnCompleteListener<Void>()
        @Override
        public void onComplete(@NonNull Task<Void> task)
        Intent intent = new Intent(YourActivity.this, NextActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);

        );






        share|improve this answer



























          2














          You can also define something like this:



          private void signOut() 
          mAuth.signOut();
          mGoogleSignInClient.signOut().addOnCompleteListener(this,
          new OnCompleteListener<Void>()
          @Override
          public void onComplete(@NonNull Task<Void> task)
          Intent intent = new Intent(YourActivity.this, NextActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
          startActivity(intent);

          );






          share|improve this answer

























            2












            2








            2







            You can also define something like this:



            private void signOut() 
            mAuth.signOut();
            mGoogleSignInClient.signOut().addOnCompleteListener(this,
            new OnCompleteListener<Void>()
            @Override
            public void onComplete(@NonNull Task<Void> task)
            Intent intent = new Intent(YourActivity.this, NextActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

            );






            share|improve this answer













            You can also define something like this:



            private void signOut() 
            mAuth.signOut();
            mGoogleSignInClient.signOut().addOnCompleteListener(this,
            new OnCompleteListener<Void>()
            @Override
            public void onComplete(@NonNull Task<Void> task)
            Intent intent = new Intent(YourActivity.this, NextActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

            );







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 12 '18 at 8:43









            Vidur ChananaVidur Chanana

            212




            212





















                0














                private void sendToLogin() //funtion
                GoogleSignInClient mGoogleSignInClient ;
                GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();
                mGoogleSignInClient = GoogleSignIn.getClient(getBaseContext(), gso);
                mGoogleSignInClient.signOut().addOnCompleteListener(/*CURRENT CLASS */.this,
                new OnCompleteListener<Void>() //signout Google
                @Override
                public void onComplete(@NonNull Task<Void> task)
                FirebaseAuth.getInstance().signOut(); //signout firebase
                Intent setupIntent = new Intent(getBaseContext(), /*To ur activity calss*/);
                Toast.makeText(getBaseContext(), "Logged Out", Toast.LENGTH_LONG).show(); //if u want to show some text
                setupIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(setupIntent);
                finish();

                );



                this code is written to work as copy past just read COMMENTS in code to customize it to ur needs, i prefer to send user to login






                share|improve this answer





























                  0














                  private void sendToLogin() //funtion
                  GoogleSignInClient mGoogleSignInClient ;
                  GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                  .requestIdToken(getString(R.string.default_web_client_id))
                  .requestEmail()
                  .build();
                  mGoogleSignInClient = GoogleSignIn.getClient(getBaseContext(), gso);
                  mGoogleSignInClient.signOut().addOnCompleteListener(/*CURRENT CLASS */.this,
                  new OnCompleteListener<Void>() //signout Google
                  @Override
                  public void onComplete(@NonNull Task<Void> task)
                  FirebaseAuth.getInstance().signOut(); //signout firebase
                  Intent setupIntent = new Intent(getBaseContext(), /*To ur activity calss*/);
                  Toast.makeText(getBaseContext(), "Logged Out", Toast.LENGTH_LONG).show(); //if u want to show some text
                  setupIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  startActivity(setupIntent);
                  finish();

                  );



                  this code is written to work as copy past just read COMMENTS in code to customize it to ur needs, i prefer to send user to login






                  share|improve this answer



























                    0












                    0








                    0







                    private void sendToLogin() //funtion
                    GoogleSignInClient mGoogleSignInClient ;
                    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail()
                    .build();
                    mGoogleSignInClient = GoogleSignIn.getClient(getBaseContext(), gso);
                    mGoogleSignInClient.signOut().addOnCompleteListener(/*CURRENT CLASS */.this,
                    new OnCompleteListener<Void>() //signout Google
                    @Override
                    public void onComplete(@NonNull Task<Void> task)
                    FirebaseAuth.getInstance().signOut(); //signout firebase
                    Intent setupIntent = new Intent(getBaseContext(), /*To ur activity calss*/);
                    Toast.makeText(getBaseContext(), "Logged Out", Toast.LENGTH_LONG).show(); //if u want to show some text
                    setupIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(setupIntent);
                    finish();

                    );



                    this code is written to work as copy past just read COMMENTS in code to customize it to ur needs, i prefer to send user to login






                    share|improve this answer















                    private void sendToLogin() //funtion
                    GoogleSignInClient mGoogleSignInClient ;
                    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail()
                    .build();
                    mGoogleSignInClient = GoogleSignIn.getClient(getBaseContext(), gso);
                    mGoogleSignInClient.signOut().addOnCompleteListener(/*CURRENT CLASS */.this,
                    new OnCompleteListener<Void>() //signout Google
                    @Override
                    public void onComplete(@NonNull Task<Void> task)
                    FirebaseAuth.getInstance().signOut(); //signout firebase
                    Intent setupIntent = new Intent(getBaseContext(), /*To ur activity calss*/);
                    Toast.makeText(getBaseContext(), "Logged Out", Toast.LENGTH_LONG).show(); //if u want to show some text
                    setupIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(setupIntent);
                    finish();

                    );



                    this code is written to work as copy past just read COMMENTS in code to customize it to ur needs, i prefer to send user to login







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 15 '18 at 11:10

























                    answered Mar 6 '18 at 11:26









                    Sumer SinghSumer Singh

                    29924




                    29924





















                        0














                        I did mGoogleSignInClient.signOut()
                        this is working as expected.






                        share|improve this answer



























                          0














                          I did mGoogleSignInClient.signOut()
                          this is working as expected.






                          share|improve this answer

























                            0












                            0








                            0







                            I did mGoogleSignInClient.signOut()
                            this is working as expected.






                            share|improve this answer













                            I did mGoogleSignInClient.signOut()
                            this is working as expected.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 31 '18 at 4:27









                            Ankit DemonstrateAnkit Demonstrate

                            13411




                            13411



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38707133%2fgoogle-firebase-sign-out-and-forget-user-in-android-app%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                這個網誌中的熱門文章

                                How to read a connectionString WITH PROVIDER in .NET Core?

                                In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                                Museum of Modern and Contemporary Art of Trento and Rovereto