Skip to content

Instantly share code, notes, and snippets.

Created February 11, 2012 11:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Store an arbitrary Bundle object into a SQLite database ref:
/* store a bundle */
Bundle bundle = // get a bundle from somewhere
final Parcel parcel = Parcel.obtain();
bundle.writeToParcel(parcel, 0);
byte[] bundleBytes = parcel.marshall();
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);
Bundle bundle = (Bundle) parcel.readBundle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment