I have a ContentProvider Class and a DatabaseHelper Class (extends SQLiteOpenHelper). The ContentProvider instantiates the Helper which needs access to a Context because the constructor requires it:
public DBHelper(Context context, AssetFileDescriptor db_as开发者_高级运维set) {
super(context, DB_NAME, null, 1);
Do you know at least a single way to get the Context from the ContentProvider?
Thanks :)
In your ContentProvider.onCreate method you can pass the result of getContext() to the DBHelper
@Override
public boolean onCreate() {
dbHelper = new DBHelper(getContext(), db_asset);
return true;
}
Do you know at least a single way to get the Context from the ContentProvider?
ContentProvider:getContext()
Try this my friend:
SampleClass sample = new SampleClass(this.getContext());
Where this
refer to the class that extends the ContentProvider...
And .getContext()
will get the context of the class that extends the ContentProvider..
Hope this one helps..
精彩评论