Search code examples
androidandroid-cursoradapter

What are the differences between setFilterQueryProvider() and runQueryOnBackgroundThread() in CursorAdapter?


I don't quite understand, is the provider means ContentProvider? Or I think they are the same.

Any ideas?


Solution

  • The documentation for those methods is pretty clear:

    Runs a query with the specified constraint. This query is requested by the filter attached to this adapter. The query is provided by a FilterQueryProvider. If no provider is specified, the current cursor is not filtered and returned. After this method returns the resulting cursor is passed to changeCursor(android.database.Cursor) and the previous cursor is closed. This method is always executed on a background thread, not on the application's main thread (or UI thread.) Contract: when constraint is null or empty, the original results, prior to any filtering, must be returned.

    Under the hood the runQueryOnbackgroundThread() method simply runs the runQuery() method of the FilterQueryProvider if one is provided. You would use the FilterQueryProvider when you need to filter the CursorAdapter without creating a subclass, if you extend CursorAdapter you could choose between still providing a FilterQueryProvider or overriding the runQueryOnbackgroundThread() method.

    FilterQueryProvider has nothing to do with a ContentProvider:

    This class can be used by external clients of CursorAdapter and CursorTreeAdapter to define how the content of the adapter should be filtered.