Android App Development | Lecture#27 | Hive Learners

Words
298
Reading
2 min
Listen
Play
4y

𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼

Hello, dear members of Hive Learners, I hope you all are doing good. Today we will continue our Android App Development lecture series with the 27th lecture. And in this lecture, we will use a logout button to remove the session and also check for the excise account so that security will be maintained. We are doing this whole signing signup activity by suing the internal store in the future we will use firebase to handle it. Before that, we have to learn all the manual logic. So let's get started.

alt

GitHub Link

Use this GitHub project to clone into your directory. It will constantly get updated in the following lecture so you will never miss the latest code. Happy Coding!.

What Should I Learn

  • How to implement the login button
  • Check account existence

Assignment

  • Design a welcome screen and store the login session

Procedure

Firstly, We need to adjust the logout button on the Welcome screen design page. I set it under the username textview. I am using a vector for this button.

alt

I am using this icon to show the logout button. The name is changed so don't confuse.

alt

Here is the code for the logout button. You can adjust it anywhere on the welcome page.

    <com.google.android.material.button.MaterialButton
        style="@style/Widget.AppCompat.ImageButton"
        android:id="@+id/logout_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        app:icon="@drawable/ic_logout_24"
        android:backgroundTint="@android:color/transparent"
        app:iconTint="@color/black"
        android:background="@null"
        app:iconPadding="4dp"
        android:text="Logout"
        android:gravity="center"/>

alt

Now we need to declare and initialize this logout button in the welcome screen java activity. We also write the logic in the OnClick listener of this button.

  logout_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sharedPreferences.edit().remove("login_account").apply();
                startActivity(new Intent(Welcome_Activity.this, MainActivity.class));
                Toast.makeText(Welcome_Activity.this, "Logout Successfully", Toast.LENGTH_SHORT).show();
                finish();


            }
        });

alt

Now we also need to check if the account already exists or not on the Main Activity page. That is our signup page. we need to set a check before creating an account.

        if (sharedPreferences.contains(email)) {
            email_et.setError("Already exist");
            Toast.makeText(this, "Account already exist", Toast.LENGTH_SHORT).show();
            return;
        }

alt

So that's all for today, You must do it by yourself with better logic. Thank You. See you in the next lecture.



hl_divider.png

Thank You

hl_footer_banner.png

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