开发者

Storing in Intent in an SQLite database with android

I have an android appand I want to store a开发者_JAVA百科n android Intent in the database as a blob field. I know the basics of storing and retrieving data of TEXT, INTEGER, etc, standards types in SQLite as my app already does all of that. I am not familiar with storing and retrieving blobs. I am presuming the blob is the best way, versus storing as a string and parsing back to and Intent. Maybe that is not a correct assumption though. The intents can be a package name, URI, may have extras, etc. That is why I would like to store/retrieve the whole intent and not just store parts.


You can simply store the intent in a String way:

String intentDescription = intent.toUri(0);
//Save the intent string into your database

Later you can restore the Intent:

String intentDescription = cursor.getString(intentIndex);    
Intent intent = Intent.parseUri(intentDescription, 0);


Use the Parcelable interface with the Intent:

Parcel  parcel;  
myIntent.writeToParcel(parcel);

ContentValues values = new ContentValues();  
values.put(MyField, parcel.createByteArray());  
getContentResolver().insert(MyBaseColumn.MyTable.CONTENT_URI, values);

Reverse the process to get it out.

If you prefer text, then you could consider using json.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜