3

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

WaterBoy
  • 697
  • 3
  • 13
  • 35

1 Answers1

1

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?

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307