I am using Parse to save my data from my mobile application in the Sign-Up page. I have a field in my object with type "file", named "photo" which takes an image either from camera or from gallery of phone.
My object named 'User' (already exists - ParseUser-, I just added new fields):
The problem from the below code, is that the image is being saved to the previous user I added with the
user.getCurrentUser().put()
and when I just use the user.put()
, I can't save any data and I see the toast
that "an error has occured".
This is the way I am trying to save all the data:
ParseUser user = new ParseUser();
ParseFile file = null;
user.setPassword(password);
user.setEmail(email);
user.setUsername(username);
user.put("gender", gender);
user.put("age_category", age);
user.put("admin", false);
user.put("premium", false);
user.put("about_me", about);
user.put("reward", 0);
if (flag_photo) {
file = new ParseFile("profile_pic.jpg", image);
user.put("photo", file);
user.saveInBackground();
//user.getParseUser(String.valueOf(user)).saveInBackground();
}
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
Intent intent = new Intent(SignUpActivity.this, LoginActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.push_down_in, R.anim.push_down_out);
finish();
}
else {
int duration = Toast.LENGTH_LONG;
Toast.makeText(SignUpActivity.this, "An error occurred. Please try again!", duration).show();
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
}