O'Reilly logo

Firebase Cookbook by Houssem Yahiaoui

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Now, let's see how we can make the functionality work:

  1. Declare the FirebaseAuth reference, plus add another variable that we will need later on:
     FirebaseAuth auth;      private static final int RC_SIGN_IN = 17;
  1. Now, inside your onCreate method, add the following code:
     auth = FirebaseAuth.getInstance();      if(auth.getCurrentUser() != null) {          Log.d("Auth", "Logged in successfully");      } else {          startActivityForResult(            AuthUI.getInstance()             .createSignInIntentBuilder()              .setAvailableProviders(               Arrays.asList(new                 AuthUI.IdpConfig.Builder(                                                                  AuthUI.EMAIL_PROVIDER).build())).build(),                     RC_SIGN_IN);findViewById(R.id.logoutBtn)        .setOnClickListener(this);
  1. Now, in your activity, implement the View.OnClick listener. So your class will look ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required