Created
February 11, 2012 11:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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