In the application, the database is accessed via the CursorLoader and ContentProvider. The data cursor is created in the method:

public Loader onCreateLoader( int id, Bundle args ) { Loader cur; cur = new CursorLoader( this, ContractClass.Data.CONTENT_URI, ContractClass.Data.DEFAULT_PROJECTION, null, null, null) return cur; } 

It is necessary to create a query to the database to join two tables. As I understand it, such a query can be executed only with rawQuery (); There are some difficulties. I don’t understand how to fulfill a raw request through a loader. In general, initially in the application, access to the database was made through the heirs of AsyncTask, then I was advised to use ContentProvider. The application was rewritten for it, and from that moment all the difficulties started, I don’t understand at all, why use it if you don’t need to share the application database. Maybe better roll back before it's too late?

  • How is the ContentProvider implemented? In theory, you process loader requests in it, and you need to do rawQuery in it. - xkor pm
  • @xkor The query method is overridden in the ContentProvider and all requests occur through it. But I understand. CursorLoader calls this method when creating the CursorLoader itself with parameters passed through the constructor. I can't figure out how to put a query with several tables and a JOIN ON clause in the CursorLoader constructor's parameters (Context context, Uri uri, String [] projection, String selection, String [] selectionArgs, String sortOrder), and later process it in the redefined method query inherited from ContentProvider - Evgeny Kuznetsov

1 answer 1

When working with ContentProvider and CursorLoader, you have to come up with for each request a uri in which you can distinguish this uri from the uri for other requests and which will have all the parameters required for the request. Further, in the query method of your ContentProvider, parse the uri, determine what kind of query you need to execute, what parameters it has, and based on this, build an SQL query, and execute it.

  • If the request is built dynamically based on user input, you will need to invent a scheme that will encrypt the request in uri, then transfer it and further parse the necessary parameters, and depending on the query in the query ContentProvider method, call the corresponding method of the class SQLiteDatabase - rawQuery, query or some other? I understand correctly? - Evgeny Kuznetsov
  • Well, something like that - xkor