Desafortunadamente, ContentResolver no puede realizar consultas teniendo un argumento de límite. Dentro de su ContentProvider, su MySQLQueryBuilder puede consultar agregando el parámetro de límite adicional.
Siguiendo la agenda, podemos agregar una regla de URI adicional dentro de ContentProvider.
static final int ELEMENTS_LIMIT = 5;
public static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
........
uriMatcher.addURI(AUTHORITY, "elements/limit/#", ELEMENTS_LIMIT);
}
Luego, en el método de consulta
String limit = null; //default....
switch(uriMatcher.match(uri)){
.......
case ELEMENTS_LIMIT:
limit = uri.getPathSegments().get(2);
break;
......
}
return mySQLBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder, limit);
Consulta ContentProvider de actividad.
uri = Uri.parse("content://" + ContentProvider.AUTHORITY + "/elements/limit/" + 1);
//In My case I want to sort and get the greatest value in an X column. So having the column sorted and limiting to 1 works.
Cursor query = resolver.query(uri,
new String[]{YOUR_COLUMNS},
null,
null,
(X_COLUMN + " desc"));
Solo una idea. Pero puedes intentar poner la cláusula de límite como el último parámetro. Al igual que actividad.managedQuery (lista de reproducciónUri, nulo, nulo, nulo, "límite 3")? – Renard