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 ...

Get Firebase Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.