我想将通用 POJO 放入 ContentValues 中并在 ContentProvider 中解组它。
我一直在绞尽脑汁地思考:Parcelables、ContentValues 和插入 SQLite
关于:http://njzk2.wordpress.com/2013/05/31/map-to-contentvalues-abusing-parcelable/ http://njzk2.wordpress.com/2013/05/31/map-to-contentvalues-abusing-parcelable/
如何编写在android的Sqlite中插入数据的通用代码 https://stackoverflow.com/questions/23244834/how-to-write-a-common-code-for-inserting-data-in-androids-sqlite
我一直在尝试通过 ContentProvider 将 android.location.Location 插入到 SQLite 中:
Location loc = mLocationClient.getLastLocation();
myParcel = android.os.Parcel.obtain();
loc.writeToParcel(myParcel, 0);
ContentValues values = ContentValues.CREATOR.createFromParcel(myParcel );
用地块填充值。
问题1)
这是我的 ContentProvider.insert 方法:
@Override
public Uri insert( final Uri uri, final ContentValues values ){
SQLiteDatabase db = Mydatabase.getWritableDatabase();
//db.insert() doesn’t unmarshal the values??
db.insert( myTABLE_NAME, “”, values);
Uri result = null;
db.close();
return result;
}
这失败了,因为 db.insert() 没有解组值(我相信)
插入 android.database.sqlite.SQLiteException 时出错:INSERT INTO myTABLE_NAME() VALUES (NULL)
问题2)
有什么方法可以先解组值,然后将其编组回另一个 ContentValues 变量吗?也许w/ getKey()???