Reputation: 83
i had created class that extends contentprovider. I had override the 6 functions
@override
public Uri insert(Uri uri, ContentValues initialvalues) {
ContentValues values;
if(initialvalues != null){
values = new ContentValues(initialvalues);
}else{
values = new ContentValues();
}
SQLiteDatabase mDb = mDbHelper.getWritableDatabase();
long rowId = mDb.insert(DatabaseHelper.TABLE_PROGRAM, null, values);
if(rowId > 0){
Uri programUri = ContentUris.withAppendedId(null, rowId);
getContext().getContentResolver().notifyChange(programUri, null);
return programUri;
}
throw new IllegalArgumentException("Failed to insert row into " + uri);
}
private void createdata(){
String a = "a", b = "b", c = "c", d= "d";
//how i going to call the content provider to let me to add in data?
}
my question is how to call the insert() to add data?
Upvotes: 0
Views: 943
Reputation:
Obtain ContentResolver instance via getContentResolver() insert method.
UPDATE That's the best tutorial
Upvotes: 1