Reputation: 61
I've been trying to get a registration/login form going on in my android application, and I've been trying to do so with the help of the Parse Core by storing users' information as an Object.
I've gotten everything to work perfectly. Well...almost.
The only thing that I need to do now is to add a unique user ID for every user registered and increment it by 1 everytime a new user registers.
I've tried using the Users.increment("userID", 1);
, and it works, but it doesn't go over the value 1
.
This is what I'm trying to do:
This is my registration form code:
ParseObject Users = new ParseObject("Users");
Users.increment("userID", 1);
Users.put("first_name", firstname);
Users.put("last_name", lastname);
Users.put("email", email);
Users.put("password", password);
Users.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
//User registered successfully.
Toast.makeText(RegisterActivity.this, "Registration successful."
, Toast.LENGTH_SHORT).show();
//Take user to LoginActivity.
startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
} else {
//User registration failed.
Toast.makeText(RegisterActivity.this, "Registration failed."
, Toast.LENGTH_SHORT).show();
//Show error.
e.printStackTrace();
}
}
});
Thank you for your time.
Upvotes: 0
Views: 69
Reputation: 25194
When you write ParseObject user = new ParseObject("Users");
you are defining a new row of the table, so if you call increment()
you will be incrementing just that row's value.
If you want to do something different I can help you out. The answer is different based on what you want to do:
and why you want to do it. Note that each user has already a unique identifier, in the objectId
field, and that can be helpful in most, if not all, applications.
Ok, now I have seen your second screenshots and understand what you are trying to achieve. That is surely possible, but I would discourage it. For example, let's say you manage to write working code. What happens if..:
The user with userID = 1 deletes his account? Are you going to scale down the userIDs of all the users that registered after (userID = 2, 3, ...)? That is hard and mostly useless.
Two or more users register at the same time? That would determine serious synchronization issues and you could end up having two (or more) users with the same userID.
So my answer is: what you want is possible only with hard work, and probably useless. If you give additional info about why you want to do that, we can find a better way.
Upvotes: 1