Home » Android » passing the same data from two different activites to a certain activity

passing the same data from two different activites to a certain activity

Posted by: admin November 1, 2017 Leave a comment

Questions:

I’m working on a project on Android Studio! Currently, I have three main activities (Sign up, Sign in, Profiles). The Signup activity takes the name of the user, his birthday, password, and email (I’m using a web database to save the information of the users). after signing up and hitting the button “Sign up”. It takes me to the Profiles activity where I can find the username and the birthday that the user has just entered while signing up. this is exactly how I want it to be. I simply used the intent method to pass the name and birthday from Signup to Profiles activity and it worked. BUT I want the same two variables (the username and the birthday)to show in the Profiles activity WHEN I sign in!! The problem is that the Sign in Activity takes only the email and the password of the user! so I can’t simply pass the username and the birthday from the Sign in, to the Profiles because in this case they are not initialized already(because I only have the email and the password here), so I can’t pass them easily using intent like I did in the Signup activity. PLEASE help me do this!

Note: maybe taking the stored information in the Database might help in this case, but I don’t know how to do it properly.

Answers:

I think that is the only way to do this.. store your user related values in some database/storage or shared preference when they signup and then later use them when they are signing in.

A simple way of implementing this could be:

When Signing up–>

  1. On Signup : Get the userName, his birthday, password, and email and store them locally in shared preferences
  2. On Profiles: Read the values from shared preferences.

When Signing in–>

  1. On SignIn–> Take only the email and the password and if successful
  2. On Profiles: Read the values from shared preferences.

Although, I’d prefer that the web service that you are using to authenticate the user should return a UserProfile type of object which will contain these basic values for the user. So it won’t matter whether you’re signing up or signing in, the information going to your Profiles Activity will be the same.