0

I am having lots of trouble with variable and parse Querys. Some of my solutions are to create a method and put parameters into it and call it from the query and insert the values that i need as parameters. but i need to make use of those values in onCreate. When put this variables as Global

ParseObject empresa;
    String stringEmpresa;
    String tipoDeEmpresa;
    String tipoEmpresa;
    String role;

and the put the values inside the query when I use them on onCreate they are null.

public void parseQuery(){

        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.include("Empresa");
        query.include("ComercialAsignado");
        query.include("ComercialTallerAsignado");
        query.getInBackground(ParseUser.getCurrentUser().getObjectId(), new GetCallback<ParseUser>() {
            @Override
            public void done(ParseUser object, ParseException e) {

                if (e == null) {
                    queryEmpresa();

                    tipoDeEmpresa = object.getString("tipoDeEmpresa");

                    role = object.getString("Rol");

                    initBottomFromRolUser(role, tipoDeEmpresa);

                    showItemNVFromRol(role, tipoDeEmpresa);

                    initFloatingButton(tipoDeEmpresa);


                }
            }
        });

Query method I also tried to retrieve the data with another method but it retrieves the wrong data, here is a screenshot. The other problem is that is not retrieving all the columns presented in my user class, this is why

tipoEmpresa=user.getString("tipoDeEmpresa");

this is null.

Also note that my Rol for demo3 is Administrador, not Usuario.

Current Rol

Remember setting those global variables inside the done method doesn't let me use these variables in onCreate

Felipe Franco
  • 171
  • 3
  • 15

1 Answers1

1

Felipe, the code you posted here does not reflect the one on your screenshot.

Would you please test it with a fixed objectId just so we can know the problem is not coming from ParseUser.getCurrentUser().getObjectId()?

Test it like this please:

final String objectIdOfUser = "LJ9AongycH";
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.getInBackground(objectIdOfUser, new GetCallback<ParseUser>() {
    @Override
    public void done(ParseUser object, ParseException e) {
        if (e == null) {
            // The query was successful, returns the users that matches
            // the criterias.
            System.out.println(objectIdOfUser + " " + object.getString("Rol"));
            System.out.println(objectIdOfUser + " " + object.getString("tipoDeEmpresa"));
        } else {
            // Something went wrong.
        }
    }
});
user3472897
  • 240
  • 2
  • 3
  • 11
  • Yes i did that i have it in the buttom of my class and i call that method in start of my class that worked perfect .. the problem is what i describe i cannot use those variables in onCreate – Felipe Franco Sep 06 '19 at 21:58