Android App Development | Lecture#34 | Hive Learners

Words
245
Reading
2 min
Listen
Play
4y

饾摉饾摶饾摦饾摦饾摻饾摬饾摲饾摪饾摷

Hello mates, I hope you all are well. In the last lecture, we cover sign-up using the FirebaseAuth. After the signup, it is necessary to take the user to the login page, So that the user can easily sign in and use the app. We will use FirebaseAuth to write the code for signing. Let's get started.

alt

GitHub Link

Use this GitHub project to clone into your directory. The following lecture will constantly update it so you will never miss the latest code. Happy Coding!

What Should I Learn

  • How to create a User in Firebase
  • Save user information

Assignment

  • Create a sign-up logic using Firebase Authentication.

Procedure

We will write all the code in the Sign in Activity. We already have two Buttons on the Main Screen to navigate to the Signup and Sign in page. yesterday we create a user but forget to add the INTERNET permission in the manifest. So follow this step to add the permission.

    <uses-permission android:name="android.permission.INTERNET" />

alt

Declare and initialize the FirebaseAuth in the sign-in activity. Remove old sign-in logic from the sign-in button click listener but make sure the checks are there.

alt

Now write the code to sign in the user with the given email and password and implement the listeners.

alt

Check if the task is successful or not and show the ProgrssDialod and AlertDialog as we use in the lecture 33 part 2. We will also open the Welcome p[age on the successful login.

firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(task -> {
                    if (task.isSuccessful()) {
                        if (progressDialog.isShowing())
                            progressDialog.cancel();

                        alertDialog.setTitle("Successful");
                        alertDialog.setMessage("You are successfully sign in");
                        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", (dialog, which) -> {
                            dialog.cancel();
                            startActivity(new Intent(SignIn_Activity.this, Welcome_Activity.class));
                            finish();

                        });
                        alertDialog.show();
                    } else {
                        if (progressDialog.isShowing())
                            progressDialog.cancel();

                        alertDialog.setTitle("Failed");
                        alertDialog.setMessage(task.getException().getMessage());
                        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", (dialog, which) -> {
                            dialog.cancel();

                        });
                        alertDialog.show();
                    }


                });

alt

hl_divider.png

Thank You

hl_footer_banner.png

Android App Development | Lecture#34 | Hive Learners | Ecency