Search code examples
androidrealmrealm-list

Realm Java - how to keep the order of the items when querying for multiple ids?


I am using Realm for android 1.2.0 and when querying for multiple ids:

query.in(Constants.ID, arraysOfIdsString);

The results are not returned in the order given in the array. Is this a realm bug? Can i preserve somehow the order of the ids with the order of the elements returned?


Solution

  • You can specify a sort order when doing the query:

    query.int(Constants.ID, arrayOfIdString).findAllSorted(Constants.ID, Sort.DESC);

    But if your list of Id's in the array is different than what is possible through sorting them either ASC or DESC, then that is unfortunately not possible.