Android Question KeyValueStore

JoséCarlos

Member
Licensed User
I created a KeyValueStore with lots of data and put it in DirAssets.
Later I copied from DirAssests to DirInternal to use, however when I access the data it doesn't exist!
Please what am I doing wrong?
 

josejad

Expert
Licensed User
Longtime User
How have your created the KeyValueStore?
You don't have to copy from any place, just initialize it
From this post:

B4X:
    xui.SetDataFolder("kvs")
    kvs.Initialize(xui.DefaultFolder, "kvs.dat")
    kvs.Put("time", DateTime.Now)
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
But, how have you saved the data in the computer?
Please, show the code you've used.

Sorry, I don't speak portuguese (but I'd love it)
 
Upvote 0

JoséCarlos

Member
Licensed User
I used B4J, saved it to datastore2.dat and copied it to DirAssets.
Later in the app I copied it to DirInternal.

B4X:
    Public kvs As KeyValueStore
    kvs.Initialize("H:\B4J\Projetos\AtualizarDadosKVS\", "datastore2.dat")
    Root = Root1
    Root.LoadLayout("MainPage")
    Dim FileName As String = "lista.json"
    Dim TargetDir As String = "H:\B4J\Projetos\AtualizarDadosKVS\"
    Dim ajson As String = File.ReadString( TargetDir,FileName)
    Dim parser As JSONParser
    parser.Initialize( ajson )
    Dim MapJson As Map = parser.NextObject
    Dim myMap As Map 'mapa auxiliar para navegação
    Dim ListaDados As List
    myMap = MapJson.Get("tudo")
    ListaDados = myMap.Get("dados")
    For i = 0 To ListaDados.Size - 1
        myMap = ListaDados.Get(i)
        kvs.Put(myMap.Get("Numero"), "{'data':"&"'"&myMap.Get("data")&"'"&","&"'lista'"&":"& myMap.Get("lista")&"}")
        If myMap.Get("Numero") = "2303" Then
'            Exit
        End If
        Log(myMap.Get("Numero")&"  "&myMap.Get("data")&"  "&myMap.Get("lista"))
    Next
 
Upvote 0

JoséCarlos

Member
Licensed User
I sincerely apologize about this for not posting.
I fixed the error, the problem is that the DirAssests folder would not delete or copy if the file did not have a xxxxx.yyy ending and I was using only xxxxx without .yyy
Thank you for your attention and once again I'm sorry.
I'm new to the forum, but I'm learning.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…