KeyValueStore on boot up

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi All

If you have a service app and the main process_Globals do the following;

Sub Process_Globals

Dim KVS As KeyValueStore
Dim SQLDB As SQL

' // no SD card - fail on boot
If File.ExternalWritable = False Then
'SQLDB.Initialize(File.DirInternal, "db_tpa", True)
KVS.Initialize(File.DirInternal, "db_kvs")
Else
'SQLDB.Initialize(File.DirDefaultExternal , "db_tpa", True)
KVS.Initialize(File.DirDefaultExternal, "db_kvs")
End If

end sub

when the app load after a REBOOT of the phone you will get a message on the screen saying;

Unfortunatly, {appname} has stopped.

To discover this I initially thought it was the notification bar, it was'nt, wrote a simple app that put an icon in the bar and when pressed the main activiy is called and 'hello world is displayed'.

So, went to the real app and rem'd out all the code to simplete the hello world app, and slowly started to re-introduce the code back in, starting with the process_Globals of activity main.

I would like to know why this happens. We are using an SQL db also and it get initialised ok. I can move the KVS into the main SQL db but would still like to know the reason for the failure.

Other should try this to see if they get the same results.

Regards

John.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should only use Process_Globals to declare variables or for simple assignments.

Depending on your application you have several options:
- Initialize the store from Service_Create.
- Add a code module that is responsible for the initialization. You can then call it from Activity_Create and Service_Create. The code in the code module should only initialize it if it wasn't initialized before.
 
Upvote 0
Top