Android App Development | Lecture#34 | Hive Learners

𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼

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.

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" />

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.

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

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();
                    }


                });


hl_divider.png

Thank You

hl_footer_banner.png



0
0
0.000
1 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000