Skip to content
Advertisement

Is there any way to just pass a “user” object instead of all the variables of user

I have a login page, and right now after the user logs in I pass all of its data like the username, password and etc. I wanted to know if it’s possible that I just pass like a whole user and it that user object I can just use getter and setters to get the user-related info. I am working on this project with Firebase so maybe perhaps I can check for current users logged in or something, I am not really sure what approach is the most suitable for this. Please let me know if there is any method like this.

How I currently pass data:

JavaScript

How my user looks like in Firebase

Advertisement

Answer

Is there any way to just pass a “user” object instead of all the variables of the user?

For sure there is. Instead of adding all of those values, you can add the entire user object. But to achieve this, you have to create a model class that looks like this:

JavaScript

Don’t forget the implement the Serializable interface. Now to add the object to the intent, please create it like this:

JavaScript

And to get it back in the other activity, please use the following lines of code:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement