I have 3 elements to my application: 1. UI (activity) 2. Model (class) 3. content provider - provides data from a database
In order for the model class to access the data from the content provider I need the UI (activity) to pass it a ContentResolver - this way I can create a cursor in the model class:
cursor = mContentResolver.query(
MyobiliseData.CONTENT_URI_RUNSUMMARY, // The content URI of the words table
projection, // The columns to return for each row
selectionClause, // Selection criteria
selectionArgs, // Selection criteria
null); // The sort order for the returned rows
Is this acceptable practice, or is there a better way to call the content provider from a non-activity class?
thanks
anton
It is a common pattern to provide context from Activity to other classes, and then use context to obtain various objects via context getter methods, including getContentResolver(). See for example the answers to How can I call getContentResolver in android?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With