Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is passing a ContentResolver risky?

Tags:

android

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

like image 529
WaterBoy Avatar asked Dec 05 '25 10:12

WaterBoy


1 Answers

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?

like image 96
Alex Cohn Avatar answered Dec 08 '25 00:12

Alex Cohn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!