Android Question [Solved]keyValueStore2 ?

anOparator

Active Member
Licensed User
Longtime User
I added Button1 to the keyValueStore2 example, it increments the value Starter.pos.
The value persists when opening from 'Recent Apps' but gets re-initialized if the app is closed and re-opened.
I can see that datastore22 is updated each time the app closes.

B4X:
Sub Button1_Click
   Starter.pos = Starter.pos + 1
   Starter.kvs.Put("numbers", Starter.pos)     'updates Pos, not persistent     
   Log("Button1_Click update Pos = " & Starter.pos)
End Sub
I even tried a few If/Else statements in Starter_Create but still need a pointer on how to get around the re-initialize issue.
B4X:
#Region  Service Attributes

Sub Process_Globals
   Public kvs As KeyValueStore
   Dim pos = 4 As Int[\code]
End Sub

Sub Service_Create
   kvs.Initialize(File.DirDefaultExternal, "datastore22")   '
   Log("Service_Create pos= " & (kvs.Get("numbers")))
End Sub
added the project file.
 
Last edited:

anOparator

Active Member
Licensed User
Longtime User
I added Button1 to the keyValueStore2 example, it increments the value Starter.pos.
The value persists when opening from 'Recent Apps' but gets re-initialized if the app is closed and re-opened.
I can see that datastore22 is updated each time the app closes.

B4X:
Sub Button1_Click
   Starter.pos = Starter.pos + 1
   Starter.kvs.Put("numbers", Starter.pos)     'updates Pos, not persistent     
   Log("Button1_Click update Pos = " & Starter.pos)
End Sub
I even tried a few If/Else statements in Starter_Create but still need a pointer on how to get around the re-initialize issue.
B4X:
#Region  Service Attributes

Sub Process_Globals
   Public kvs As KeyValueStore
   Dim pos = 4 As Int[\code]
End Sub

Sub Service_Create
   kvs.Initialize(File.DirDefaultExternal, "datastore22")   '
   Log("Service_Create pos= " & (kvs.Get("numbers")))
End Sub
added the project file.
added to Activity_Resume
B4X:
Starter.kvs.Get("numbers ")
and the updated 'pos' value persists.
Now to get Button1_Click to get in sync.
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
OK, I was thinking too much.
B4X:
Button1_Click
Starter.pos = Starter.pos + 1
Starter.kvs.Put("numbers ", Starter.pos)
Nothing needed in Activity_Pause or Resume.
Also cleaned Service-Proces global and Create.
Thanks for the forum material.
 

Attachments

  • tmp_kvs2.1Test-831110212.zip
    11.6 KB · Views: 162
Upvote 0
Top