Android Tutorial KeyValueStore class - Simple and efficient key/value data store

Status
Not open for further replies.

bluedude

Well-Known Member
Licensed User
Longtime User
Erel,

I have an app. with 5-6 activities which all use a database. I declare the keyvaluestore in a code module to make sure it is available to all activities. However, I noticed I get errors when I don't initialize the keyvaluestore again in every activity.

This happens when android destroys my activity.

In code module
Sub prepareStorage
If kvs.IsInitialized =False Then
kvs.Initialize(File.DirDefaultExternal,"datastore")
Else
End If
'storage of variants
kvs.createTable ("test")
end sub

I just call this when main activity is loaded for the first time.

I already noticed I can solve the problem when calling it in every activity by using firsttime, not sure If I want that.
 

cbal03

Member
Licensed User
Longtime User
why not do it in main, activity_create, if(firsttime)...?

Then reference it by main.kvs?
 

Peter van Hoof

Member
Licensed User
Longtime User
Doubles stored to the KeyValueStore using PutSimple are rounded after 6 decimals after the period even if you first store them in a string. this is a problem in the app i am developing at the moment that needs to store GPS coordinates.

I can store a double by adding a character to the start of the string and stripping it off after retrieving it but is there a more elegant way to do this?
 

JoshyDEWstive

Member
Licensed User
Longtime User
Hi Erel,
I really want to use this,
Ive downloaded it now where do i put it?;
Ive tried librarys and nope.

Thanks
 

Peter van Hoof

Member
Licensed User
Longtime User
Hi Erel,
I really want to use this,
Ive downloaded it now where do i put it?;
Ive tried librarys and nope.

Thanks

A good place to put this module would be the shared modules directory directory defined in . [tools] - [configure paths] - [shared modules] so you wont have copy's of it in all your project directory's. then as LucaMs said add it to the project with [Menu Project] - [Add Existing Module]
 

freetoair

Member
Licensed User
Longtime User
When i start the app in which the AndroidManifest.xml is read only, for skipping the verification of USB, I always get the following message:

"An error has occured in sub:Keyvaluestore_initialize (java line:257)
android.database.sqlite.SQLiteCantOpenDatabaseException:
unknown error (code 14): Could not open database
Continue?"

Otherwise when I install an APK from B4A functioning normally. But after boot always shows this message. Does it have to do with AndroidManifest.xml file?
 

freetoair

Member
Licensed User
Longtime User
No, in this case I do not get this message, but then constantly have to approve of the USB device.
 

freetoair

Member
Licensed User
Longtime User
Before that, I entered the sequence :

<intent-filter>
<action android: name = "android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</ intent-filter>
<meta-data android: name = "android.hardware.usb.action.USB_DEVICE_ATTACHED"
android: resource = "@ xml / device_filter" />

in manifest editor, and

#Region Service Attributes
#StartAtBoot: True
#End Region

And now APK does not start after boot.
 

freetoair

Member
Licensed User
Longtime User
Unfortunately now the problem is the same. Message:

"An error has occured in sub:Keyvaluestore_initialize (java line:257)
android.database.sqlite.SQLiteCantOpenDatabaseException:
unknown error (code 14): Could not open database
Continue?"

it occurs only at boot sequences. When I start APK through B4A everything is fine.
Any solution ?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…