Skip to content

Instantly share code, notes, and snippets.

@barmgeat
Last active September 15, 2018 22:28
Show Gist options
  • Save barmgeat/a7387f5d7996f5387c2ff3a84075ea8a to your computer and use it in GitHub Desktop.
Save barmgeat/a7387f5d7996f5387c2ff3a84075ea8a to your computer and use it in GitHub Desktop.
...
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
final int match = uriMatcher.match(uri);
switch (match){
case WORDS_CODE :
return insertData(uri, contentValues);
default:
throw new IllegalArgumentException("Valid URI " + uri);
}
}
/**
* @param uri : caller should provide the Uri he need
* @param content: caller should provide the Data of the inserted Object
* @return the new Uri for inserted Object
*/
private Uri insertData(Uri uri, ContentValues content) {
SQLiteDatabase database = mDbHelper.getWritableDatabase();
long id = database.insert(uri.getPath(), null, content);
if (id != -1) {
return ContentUris.withAppendedId(uri, id);
}
else{
return null ;
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment