Android App Development | Lecture#25 | Hive Learners
𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼
Greeting to all the Hive Learners, Welcome to the 25th lecture on Android App development. I hope you are learning something new day by day. Today we will work on the signing button and show a login successful message or login failed accordingly. We will also add the check as we do in the 24th lecture. I forget to convert the email to lowercase in lecture 24 so I will add the toLowerCase() function to store and get the value from the sharedPreferences.
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
- Write logic for sign-in button
Assignment
- Create a successful signing form
Procedure
First I add the same SharedPreferences as we do in lecture 24. Declare and initialize the sharedPreferences.
Then we need to add some checks to the signing button click listener.
if (TextUtils.isEmpty(email_et.getText().toString())){
email_et.setError("Invalid Email");
return;
}
if (TextUtils.isEmpty(pass_et.getText().toString())){
pass_et.setError("Invalid Password");
return;
}
Now we write logic to check the email in the shared preference. First, we check if that email exists or not and show a message Email not exist
. Then we will get the password from the sharedPreferences that is stored in mapping with the email. The data is saved as
Column 1 | Column 2 |
---|---|
myemail | mypassword |
I can get my password by calling the email that the user enters in the Email field. Then I compare the database value with the user-entered password field value.
if (!sharedPreferences.contains(email_et.getText().toString().toLowerCase())) {
Toast.makeText(SignIn_Activity.this, "Email not exist", Toast.LENGTH_SHORT).show();
} else {
String get_pass = sharedPreferences.getString(email_et.getText().toString().toLowerCase(), "");
if (pass_et.getText().toString().equals(get_pass)) {
Toast.makeText(SignIn_Activity.this, "Login Successful", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SignIn_Activity.this, "Login failed: Wrong password or email", Toast.LENGTH_SHORT).show();
}
}
Now let's run our app and check if all the logic is working or not.
Yay! 🤗
Your content has been boosted with Ecency Points, by @faisalamin.
Use Ecency daily to boost your growth on platform!
Support Ecency
Vote for new Proposal
Delegate HP and earn more
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.
Dear @faisalamin, sorry to jump in a bit off topic but may I ask you to support the HiveSQL proposal?
It lost its funding recently and your help would be much appreciated to keep the HiveSQL service free for the Hive community.
You can do it on Peakd, Ecency, Hive.blog or using HiveSigner.
Thank you for your support!
Done! Thank You for notifying us.
Thank you for your support @faisalamin, really appreciate it! 👍