Android App Development | Lecture#24 | Hive Learners
๐๐ป๐ฎ๐ฎ๐ฝ๐ฒ๐ท๐ฐ๐ผ
Hello dear community members, Today is our 24th lecture on Android App Development. Due to the EID Season, there is a delay for this lecture. I am sorry for that and also wish you all the EID MUBARAK. I hope you all are enjoying a good time with your friends and family members. Today we will set some checks in our code and save the data of a user in the internal storage for the signing and signup. So let's jump into it.
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 set checks
- Save data in SharedPreferences
Assignment
- Create Check and save data
Procedure
First, we set some checks in the signup java code. Here are the checks for the name, email, password, and a check to compare the text in the password field with the text in the confirm password field. If any check failed then it will show an error in the target field. And the return
stop the code to execute further. I use a built-in function TextUtils to implement these checks.
if (TextUtils.isEmpty(name_et.getText())) {
name_et.setError("Invalid Name");
return;
}
if (TextUtils.isEmpty(email_et.getText())) {
email_et.setError("Invalid Email");
return;
}
if (TextUtils.isEmpty(pass_et.getText())) {
pass_et.setError("Invalid Password");
return;
}
if (!(pass_et.getText().toString().equals(confirm_pass_et.getText().toString()))) {
Toast.makeText(MainActivity.this, "Password not matching", Toast.LENGTH_SHORT).show();
return;
}
Now we create a function create_user
with three parameters name, email, and password. Also, declare SharedPreferece. It will be used to save data in internal storage. It is not safe for security reasons. But will only learn it to use for different purposes rather than signing signup.
private SharedPreferences sharedPreferences;
We also need to initialize the sharedPreferences.
sharedPreferences = getSharedPreferences("sharedPreferences", Context.MODE_PRIVATE);
Now we will implement the logic in the create_user function to store the data.
public void create_user(String name, String email, String password) {
sharedPreferences.edit().putString(email, password).apply();
sharedPreferences.edit().putString(email + "_name", name).apply();
Toast.makeText(this, "Account created successfully", Toast.LENGTH_SHORT).show();
startActivity(new Intent(MainActivity.this, SignIn_Activity.class));
finish();
}
Now we need to call this function in the sign_up button click after the checks. This will create a new user and the data will save in internal private storage.
Doing the checks is very important for the software ! thanks
!1UP
Click this banner to join "The Cartel" discord server to know more.
Yeah. It will prevent the wrong input.
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.
PIZZA Holders sent $PIZZA tips in this post's comments:
@curation-cartel(10/20) tipped @faisalamin (x1)
Please vote for pizza.witness!
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.ย
ย
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
This is great. I really learnt alot from this. Kudos ๐
Thank You @alidickson. I am really happy that you find it useful.