Parse Anonymous Utils: how to create just one user?

I have a quick question. I am trying to enable automatic user creation in my application so that when you open it for the first time, one and only one user is created. I read the user's docs carefully and found that Parse continues the user's session on disk and that after saving an object to that user, that user is saved to the cloud. However, I noticed two problems:

1) When I save the object and create a pointer to the user Owner, the custom object does not exist in the cloud.

2) If I check if the current user is linked using ParseAnonUtils.isLinked (), this sometimes returns true, as in the current user, or false, since the current user is not linked, for the same exact ParseUser that was cached in the session.

Here is the method I use to create and define a user:

private void getUser() {
    if (!ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) {
        Log.v("Miles", "new user");
        ParseAnonymousUtils.logIn(new LogInCallback() {

            @Override
            public void done(final ParseUser user, ParseException e) {
                if (e == null) {
                  user.setUsername(UUID.randomUUID().toString());
                  user.setPassword(UUID.randomUUID().toString());
                  user.signUpInBackground(new SignUpCallback() {

                    @Override
                    public void done(ParseException e) {
                        if (e == null) {
                            user.saveInBackground(new SaveCallback() {

                                @Override
                                public void done(ParseException e) {
                                    if (e == null) {
                                        Log.v("Miles", "user saved");
                                    } else {
                                        Log.v("Miles", "user not saved " + String.valueOf(e.getCode()));
                                    }
                                }

                            });
                        } else {
                            Log.v("Miles", "signup fail " + String.valueOf(e.getCode()));
                        }
                    }
                  });
                } else {
                    Log.v("Miles", "anon login fail " + String.valueOf(e.getCode()));
                }
            }
        });
    }
}

      

Help would be greatly appreciated.

+3


source to share





All Articles