Skip to content

Instantly share code, notes, and snippets.

@peo3
Created February 11, 2012 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peo3/1798953 to your computer and use it in GitHub Desktop.
Save peo3/1798953 to your computer and use it in GitHub Desktop.
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