Android Question KeyValueStore2 ListKeys, display problem ?

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I have 2 keys in keysvaluestore

B4X:
Sub Process_Globals
   Public kvs As KeyValueStore
end sub

Sub btn_Clicked
    Private rec As List
    rec.Initialize
    rec.AddAll(Array As String("Account2","my account2","12345"))
    kvs.PutEncrypted( "Account2",rec,PASSWORD)

    rec.Initialize
    rec.AddAll(Array As String("Account1","my account1,"12345"))
    kvs.PutEncrypted( "Account1",rec,PASSWORD)
End Sub

When I list keyvalueStore
B4X:
Sub List
    For i = 0 To kvs.ListKeys.Size - 1
        LogColor(kvs.ListKeys.Get(i),Colors.Yellow)
    Next
End Sub

The log result in Jellybean shows keys order by input sequence
  • Account2
  • Account1
but on Pie, the order is alphabetically
  • Account1
  • Account2
Is there a way to show keys order by input sequence in every OS ?
 
Last edited:

incendio

Well-Known Member
Licensed User
Longtime User
DId you try this?
B4X:
Dim MyList As List = kvs.ListKeys
    MyList.SortCaseInsensitive(True)
Isn't those codes will sort list items alphabetically?

I want to display item in list according to the input sequence.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I want to display item in list according to the input sequence.
Can the data be entered this way whenstored in kvs. If so, then I can see a solution to the order desired:
B4X:
PASSWORD  ="12345"
    rec.Add("1, Account2,my account2, "& PASSWORD)
    kvs.PutEncrypted( "Account2",rec,PASSWORD)

    PASSWORD ="12445"
    rec.Add("2, Account1,my account1," & PASSWORD)
    kvs.PutEncrypted( "Account1",rec,PASSWORD)

    PASSWORD ="67345"
    rec.Add("3, Account3,my account3," & PASSWORD)
    kvs.PutEncrypted( "Account3",rec,PASSWORD)
We can achieve this order you are looking for:
Account2
Account1
Account3
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Use KeyValueStore2 class and change its:
B4X:
'creates the main table (if it does not exist)
Private Sub CreateTable
    sql1.ExecNonQuery("CREATE TABLE IF NOT EXISTS main(key TEXT PRIMARY KEY, value NONE)")
End Sub

to:
B4X:
'creates the main table (if it does not exist)
Private Sub CreateTable
    sql1.ExecNonQuery("CREATE TABLE IF NOT EXISTS main(key TEXT, value NONE)")
End Sub

Deselect the library, of course, and delete the previous kvs file, if it exists.
 
Last edited:
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Thanks all for your help.

Unfortunately I have to abandon this keyvalue store.

I just realize that keyvalue only encrypt value not the key. This is not enough for my need.
Perhaps, I will looking for sqlcipher or randomaccessfile to encrypt all data.
 
Upvote 0
Top