Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Store an arbitrary Bundle object into a SQLite database ref: http://qiita.com/items/2386
/* store a bundle */
Bundle bundle = // get a bundle from somewhere
final Parcel parcel = Parcel.obtain();
bundle.writeToParcel(parcel, 0);
byte[] bundleBytes = parcel.marshall();
parcel.recycle();
ContentValues values = new ContentValues();
values.put("bundle", bundleBytes);
SQLiteDatabase db = // create a db object
db.insert("table", null, values);
/* restore a bundle */
Cursor cur = // get a cursor of your db
byte[] bundleBytes = cur.getBlob(cur.getColumnIndex("bundle"));
final Parcel parcel = Parcel.obtain();
parcel.unmarshall(bundleBytes, 0, bundleBytes.length);
parcel.setDataPosition(0);
Bundle bundle = (Bundle) parcel.readBundle();
parcel.recycle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment