This question already has an answer here:
Is there a way to limit the number of rows returned from content provider? I found this solution, however, it did not work for me. All of the rows are still being returned.
Uri uri = Playlists.createIdUri(playlistId); //generates URI
uri = uri.buildUpon().appendQueryParameter("limit", "3").build();
Cursor cursor = activity.managedQuery(playlistUri, null, null, null, null);
Unfortunately, ContentResolver can't query having limit argument. Inside your ContentProvider, your MySQLQueryBuilder can query adding the additional limit parameter.
Following the agenda, we can add an additional URI rule inside ContentProvider.
Then in your query method
Querying ContentProvider from Activity.
A content provider should on general principle pay attention to a limit parameter. Unfortunately, it is not universally implemented.
For instance, when writing a content provider to handle SearchManager queries:
Where it isn't implemented you can only fall back on the ugly option of gluing a limit on the sort clause.
I have had this issue and had to break my head till I finally figured it out, or rather got a whay that worked for me. Try the following
The last parameter is for sortOrder. I provided the sort order and also appended the LIMIT to it. Make sure you give the spaces properly. I had to check the query that was being formed and this seemed to work.