Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: What does ContentResolver.update() do excactly?

I want to use the method ContentResolver.update(Uri uri, ContentValues values, String where, String[] selectionArgs) I know how to use it, but I wonder what it does with the ContentValues. Does it overwrite ALL existing ContentValues, or does it only overwrite the given ContentValues?

So for example, these ContentValues exist:

A: abc
B: 123
C: 456

And the ContentValues in the update()method contain this:

A: asdf
C: 789

Then will the new ContentValues be: (only overwrite given values)

A: asdf
B: 123
C: 789

Or will it be: (overwrite all values)

A: asdf
C: 789

This is my code:

 contentResolver.update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values, "_data=" + audioFilePath, null);

In which values contains the ContentValues that should be overwritten and audioFilePath contains the path to the audiofile (which is the value of _data).

like image 224
Xander Avatar asked Oct 19 '13 10:10

Xander


People also ask

What does ContentResolver do in Android?

The ContentResolver object parses out the URI's authority, and uses it to "resolve" the provider by comparing the authority to a system table of known providers. The ContentResolver can then dispatch the query arguments to the correct provider.

What does ContentResolver query () return?

The ContentResolver. query() client method always returns a Cursor. This cursor contains the column specified by the query projection. The cursor object provides read access to rows and columns.

What is the use of ContentResolver?

The ContentResolver object sends requests (like create, read, update, and delete) to the ContentProvider as a client.

What is a ContentProvider and what is it typically used for?

A content provider can be used to manage access to a variety of data storage sources, including both structured data, such as a SQLite relational database, or unstructured data such as image files. For more information on the types of storage available on Android, see Storage options, as well as Designing data storage.


2 Answers

It will only overwrite the given ContentValues.

like image 120
Sinu Varghese Avatar answered Sep 18 '22 23:09

Sinu Varghese


As per the documentation, all the ContentResolver.update() method does is call the update method of the ContentProvider that you've defined and identified by the URI you provide in the first argument.

So, to know exactly what's going on, you need to look at how you defined the update() method of the ContentProvider you are referencing. Take a look at the ContentProvider basics documentation. If you need help properly defining the update() method of your contentProvider, post your code here or ask a question specific to that.

like image 42
SBerg413 Avatar answered Sep 18 '22 23:09

SBerg413