### About

B4J Tutorial
http://www.b4x.com/android/forum/threads/keyvaluestore-class.36683/#content
B4A Tutorial which also applies to B4J
http://www.b4x.com/android/forum/threads/keyvaluestore-class-simple-and-efficient-key-value-data-store.26317/
Requirements
1. Additional Jar required:
#AdditionalJar: sqlite-jdbc-3.7.2
2. Additional Jar required when using encryption
Encryption library Bouncy Castle: http://www.bouncycastle.org/download/bcprov-jdk15on-154.jar
Notes:
• Copy to the additional libraries folder.
• Add to #AdditionalJar: bcprov-jdk15on-154
• Check out if there are newer versions (Status 2016.4.08 using 154)
3. Add Module to Project
As KeyValueStore is a class, copy the keyvaluestore.bas to your project folder and add the module to your project.
Init KeyValueStore
The keys and associated values are stored in an SQLite database, Table main, fiels Key (TEXT) and Value (NONE).
In the KeyValueStore Initialize Method the database location and name is set:
Private kvs As KeyValueStore
kvs.Initialize(File.DirApp, "datastore")
The database is called datastore located in the app folder (the same folder where the Jar is stored).
Usage of put and get
Text
kvs.PutSimple("simple", "Hello World")
Dim msg as String = kvs.GetSimple("simple")
Type
Type Contact(Name As String, EMail As String)
Dim ctc As Contact
ctc.Initialize
ctc.Name = "My Name"
ctc.EMail= "My EMail"
kvs.PutObject("contact", ctc)
Dim ctc As Contact = kvs.GetObject("contact")
Dim name as String = ctc.Name
Dim email as String = ctc.EMail
Bitmap
Private ivPutBitMap As ImageView
Private ivGetBitMap As ImageView
kvs.PutBitmap("bitmap", ivPutBitMap.GetImage)
Or
kvs.PutBitmap("bitmap", fx.LoadImage(File.DirAssets, "mybitmap.png"))
ivGetBitMap.SetImage(kvs.GetBitmap("bitmap"))
List
Private lstPutObjectList As ListView
kvs.PutObject("list", lstPutObjectList.Items)
Private lstGetObjectList As ListView
lstPutObjectList.Items.Clear
lstGetObjectList.Items.AddAll(kvs.GetObject("list"))
Encrypt
kvs.PutEncyptedObject("encrypt", "Hello World", "mypassword")
Dim s as String = kvs.GetEncryptedObject("encrypt", "mypassword")
Map
Dim m As Map
m.Initialize
m.Put("Key", txtPutMap.Text)
kvs.PutObject("map", m)
Dim m As Map = kvs.GetObject("map")
Dim s as string = m.Get("Key")
Get all the Keys and list in a Listview
Private lvwKeyValueStore As ListView
lvwKeyValueStore.Items.Clear
lvwKeyValueStore.Items.AddAll(kvs.ListKeys)

Changed: , Category: KeyValueStore, File: T6C212M1545.htm, ID: 1545