简体   繁体   中英

Storing in Intent in an SQLite database with android

I have an android appand I want to store an 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM