0

I am using Parse.com as my backend, and I want to download data from server. I have tags which filter these data. Unfortunately it works wrong. Lets say I have two tags "city1" and "city2", now I only get data for "city1".

public ArrayList<Dataset> getDatasetFromServer(Context context) {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Dataset");
    List<String> cities = DatabaseAdapter.getCityNames(context);
    //cities list contains "city1" and "city2"
    query.whereContainedIn("cities", Arrays.asList(cities.toArray(new String[cities.size()])));
    ArrayList<Dataset> dataset = new ArrayList<>();

    try {
        List<ParseObject> parseDataset = query.find();
        dataset = setDatasetList(parseDataset);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return dataset;
}

The problem is with this : Arrays.asList(cities.toArray(new String[cities.size()]). Don't know why, but this convertion works wrong with Parse. However, if I change above line to this

String[] array = {"city1", "city2"};
query.whereContainedIn("cities", Arrays.asList(array));

Everything works fine and I get data for city1 and city2. My question is, what's the difference between these two solutions and how to fix this so the first solution works?

EDIT : This also doesn't work :

query.whereContainedIn("cities", DatabaseAdapter.getCityNames(context));

getCityNames returns List<String>

1
  • Log what the following outputs: DatabaseAdapter.getCityNames() Commented Jan 2, 2015 at 16:32

2 Answers 2

1

Instead of converting your list to an array and then back to a list, just do this:

query.whereContainedIn("cities", cities);
Sign up to request clarification or add additional context in comments.

Comments

0

The problem was my fault. Both solutions work good. The reason it didn't worked was that my method DatabaseAdapter.getCityNames(context) put a whitespace on the beggining of second element which I didn't saw.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.