Why are LIMIT and OFFSET APIs are not working (for some devices)? #242
-
I want to implement pagination for showing the contacts to those user who have thousand's of Contacts, I wanted to use the limit and offset functionality, but they don't work in version 0.2.1 and also 0.2.2, can you please fix them ? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
@atharv-appyhigh, thanks for creating this issue and taking interest in using this library! I thought I fixed this issue in release 0.2.1. This seems to be a duplicate of #217. I will take a look at it again tomorrow morning (it's late here). This is high priority and if I'm able to reproduce it I will work on a patch ASAP! While you wait, please tell me some details about the device you are testing on. Is it an emulator? What API level is it? |
Beta Was this translation helpful? Give feedback.
-
Hi @vestrel00, first of all Thanks for creating such an amazing library, I have have looked at other feature and I was blown away by them😉. Regarding this issue, I have tested both the release 0.2.1 and also release 0.2.2 but none of them seems to address the problem, I also looked at #217 before posting it again because it didn't solve the problem. I am currently testing on "Realme RMX2151 (Realme 7)" with Api level 30 (android 11). I tested it with both BroadQuery and Query, but both of them return all of the contacts regardless of the offset and limit parameter I use. Thank you again for the library man |
Beta Was this translation helpful? Give feedback.
-
Thanks! This praise is amazing! I'll sleep good tonight 😁
It's my pleasure and thank you for using it!
Could you please test on a google pixel emulator? See if you can reproduce the issue there. Hopefully, it is reproducible there so I can repro it myself 🙏 |
Beta Was this translation helpful? Give feedback.
-
@atharv-appyhigh, this is probably specific to Realme's version of the Android OS. I ran the following code using version 0.2.2. Contacts(context).broadQuery().offset(25).limit(25).find() I am not able to reproduce this issue in the following emulators;
I am also not able to reproduce it in real physical devices I own;
Could you please see if you can reproduce this issue in an emulator or any other device? Otherwise, this issue is probably specific to "Realme RMX2151 (Realme 7)" or the Realme phones in general. I don't own a Realme phone and Genymotion does not have an image of any Realme devices, so I will need your help in debugging this issue 🙏 Could you look at the error logs and see if you see anything relevant there when you are executing your query? Otherwise, just copy-paste the entire logs and I'll look through it myself. Make sure that you do NOT include private data that you don't want to be public in the internet. So, I recommend using fake test data/contacts for this. Also, please run the following code and share the log output. This will determine whether or not this is a bug with this library or if it is a limitation from the Realme phone. val cursor1 = contentResolver.query(
ContactsContract.Contacts.CONTENT_URI,
arrayOf(ContactsContract.Contacts._ID),
null,
null,
"_id COLLATE NOCASE ASC LIMIT 25 OFFSET 25"
)
val cursor2 = contentResolver.query(
ContactsContract.Contacts.CONTENT_URI,
arrayOf(ContactsContract.Contacts._ID),
null,
null,
"_id ASC LIMIT 25 OFFSET 25"
)
val cursor3 = contentResolver.query(
ContactsContract.Contacts.CONTENT_URI,
arrayOf(ContactsContract.Contacts._ID),
null,
null,
"_id ASC LIMIT 25"
)
val cursor4 = contentResolver.query(
ContactsContract.Contacts.CONTENT_URI,
arrayOf(ContactsContract.Contacts._ID),
null,
null,
"_id LIMIT 25"
)
Log.d(
"ContactsDebug",
"""
cursor1: ${cursor1?.count}
cursor2: ${cursor2?.count}
cursor3: ${cursor3?.count}
cursor4: ${cursor4?.count}
""".trimIndent()
) In the meantime, you could optimize your query by a LOT even if pagination does not work for certain devices you are targeting. If you only need to show the display name of contacts in a list, make sure to only include the So, your code would look something like; Contacts(context)
.broadQuery()
.include(Fields.Contact.DisplayNamePrimary)
.offset(25)
.limit(25)
.findWithContext() The above query should run in less than
I recommend to keep using val isLimitBreached = result.size > limit When you need to show all data of one contact, you can do; Contacts(context)
.query()
.where { Contact.Id equalTo contact.id }
.findWithContext()
.firstOrNull()
The list -> detail pattern is typically used in all Contacts apps (AOSP Contacts, Google Contacts, Samsung Contacts, etc). |
Beta Was this translation helpful? Give feedback.
-
I think that it is issue with realme Ui only, I have also tested it on my emulator with different API versions and also some physical devices, it is a bug of phone. I have followed your optimisation techniques and it's getting my job done. I don't know what kind of sh*t os is installed in this phone. Anyways, Thanks for the help and the library, I am greatful for people like you who exist in the community. 😌 This is the output from the code above: |
Beta Was this translation helpful? Give feedback.
@atharv-appyhigh, this is probably specific to Realme's version of the Android OS.
I ran the following code using version 0.2.2.
I am not able to reproduce this issue in the following emulators;
I am also not able to reproduce it in real physical devices I own;
Could you please see if you can reproduce this issue in an emulator or any other device?
Otherwise, this issue is probably specific to "Realme RMX2151 (Realme 7)" or the Realme phones…