Android App Development | Lecture#27 | Hive Learners
๐๐ป๐ฎ๐ฎ๐ฝ๐ฒ๐ท๐ฐ๐ผ
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.
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.
I am using this icon to show the logout button. The name is changed so don't confuse.
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"/>
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();
}
});
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;
}
So that's all for today, You must do it by yourself with better logic. Thank You. See you in the next lecture.
Thank you for the contribution !!! It is a great number of tutorials!
!1UP
Click this banner to join "The Cartel" discord server to know more.
You have received a 1UP from @gwajnberg!
@stem-curator
And they will bring !PIZZA ๐.
Learn more about our delegation service to earn daily rewards. Join the Cartel on Discord.