Android – Getting Started with Firebase – 2

This tutorial is the continuation of this tutorial Android – Getting Started with Firebase – 1. In the previous tutorial we learnt about the Firebase and had created our account in Firebase. Also we have made a Registration Activity in our Android App in which we have created the new user with Email & Password in Firebase.

In this tutorial we will learn to create Login Activity and Forgot Password Activity in our App. So let’s start !!

2.2 Log In with Email & Password

  • First of all we will complete our Login Activity. In this activity we will take two EditText fields for Email & Password, & three buttons for Login and navigating to Register & Forgot Password activity.
  • Go to res ⇒ layout ⇒ activity_login.xml and copy the following code.

  • Now Go to LoginActivity.java file and paste the following code just below the package line. Here we will use signInWithEmailAndPassword() provided by Firebase, a method to sign in with email & password.

  • Lastly open AndroidManifest.xml file and make LoginActivity as launcher activity (for now) and test the login process.

  • Run the project and login with the credentials which you have used while signing up. You will get the following output.

2.3 Forgot Password – Send Reset Password Email

  • In this activity we can change our password by sending ResetPassword link in your registered email id.
  • Here we will take one EditText for Email Id and two buttons, on for Reset Password and one for going back to Login Activity.
  • Go to res ⇒ layout ⇒ activity_reset_password.xml and copy the following code.

  • Now Go to ResetPasswordActivity.java file and paste the following code just below the package line. Here we will use sendPasswordResetEmail() provided by Firebase, a method for sending password reset instructions to Email.

  • Open AndroidManifest.xml file and make ResetPasswordActivity as launcher activity (for now) and test the activity.

  • Run the project and enter the registered Email Id to get the reset password instructions on the E-Mail. You will get the following output.

2.4 Profile Screen – Home Screen After Login Activity

  • Here in this activity we will take all the above features and make our app complete.
  • In this activity we will have Change Password Button, Change Email Button, Remove User Button & Sign Out Button.
  • Go to res ⇒ layout ⇒ activity_main.xml and copy the following code.

  • Now Go to MainActivity.java file and paste the following code just below the package line. Here we will use updateEmail(), updatePassword(), delete() and signOut()  provided by Firebase, for updating email, updating password, deleting user and sign out.

  • Lastly Open AndroidManifest.xml file and make following changes.

  • Run the project and test the complete app. You will get the following output.
  • So in this tutorial we learnt about the basics of Firebase. We will be soon posting more tutorials on Firebase.
  • Thank you for visiting our tutorial. If you have any doubts or queries regarding this, you can comment below in our comment section. Don’t forget to share the tutorial if you like it.

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *