一般使用ContentValues
ContentValues contentValues = new ContentValues();
<p class="p1">contentValues.put(key, value);</p><p class="p1">context.getContentResolver().insert(url, contentValues);//其中url是Uri类型的</p>
挺好奇的,就看了一下ContentValues源码,本来想着应该是个键值对神马的,hashmap之类的,结果。。
源码中的ContentValues看着挺奇怪的
package android.content;
public final class ContentValues
implements android.os.Parcelable
{
public ContentValues() { throw new RuntimeException("Stub!"); }
public ContentValues(int size) { throw new RuntimeException("Stub!"); }
public ContentValues(android.content.ContentValues from) { throw new RuntimeException("Stub!"); }
public boolean equals(java.lang.Object object) { throw new RuntimeException("Stub!"); }
public int hashCode() { throw new RuntimeException("Stub!"); }
<span style="color:#ff0000;">public void put(java.lang.String key, java.lang.String value) { throw new RuntimeException("Stub!"); }
</span>public void putAll(android.content.ContentValues other) { throw new RuntimeException("Stub!"); }
public void put(java.lang.String key, java.lang.Byte value) { throw new RuntimeException("Stub!"); }
public void put(java.lang.String key, java.lang.Short value) { throw new RuntimeException("Stub!"); }
public void put(java.lang.String key, java.lang.Integer value) { throw new RuntimeException("Stub!"); }
public void put(java.lang.String key, java.lang.Long value) { throw new RuntimeException("Stub!"); }
public void put(java.lang.String key, java.lang.Float value) { throw new RuntimeException("Stub!"); }
public void put(java.lang.String key, java.lang.Double value) { throw new RuntimeException("Stub!"); }
public void put(java.lang.String key, java.lang.Boolean value) { throw new RuntimeException("Stub!"); }
public void put(java.lang.String key, byte[] value) { throw new RuntimeException("Stub!"); }
public void putNull(java.lang.String key) { throw new RuntimeException("Stub!"); }
public int size() { throw new RuntimeException("Stub!"); }
public void remove(java.lang.String key) { throw new RuntimeException("Stub!"); }
public void clear() { throw new RuntimeException("Stub!"); }
public boolean containsKey(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.Object get(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.String getAsString(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.Long getAsLong(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.Integer getAsInteger(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.Short getAsShort(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.Byte getAsByte(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.Double getAsDouble(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.Float getAsFloat(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.lang.Boolean getAsBoolean(java.lang.String key) { throw new RuntimeException("Stub!"); }
public byte[] getAsByteArray(java.lang.String key) { throw new RuntimeException("Stub!"); }
public java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Object>> valueSet() { throw new RuntimeException("Stub!"); }
public java.util.Set<java.lang.String> keySet() { throw new RuntimeException("Stub!"); }
public int describeContents() { throw new RuntimeException("Stub!"); }
@java.lang.SuppressWarnings(value={"deprecation"})
public void writeToParcel(android.os.Parcel parcel, int flags) { throw new RuntimeException("Stub!"); }
public java.lang.String toString() { throw new RuntimeException("Stub!"); }
public static final java.lang.String TAG = "ContentValues";
public static final android.os.Parcelable.Creator<android.content.ContentValues> CREATOR;
static { CREATOR = null; }
}