Android Question Doubts regarding KeyValueStore and its Value updates

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

  1. I would like to know the best way OR the expected way to update the VALUE of an already existing KEY in KeyValueStore database.

  • Should I delete the Key and its value first and then Create a new Key and the New Value using kvs.putsimple / kvs.PutEncrypted ?
  • For eg.
    B4X:
    If Starter.kvs.ContainsKey("SmtpDetails") Then
        Starter.kvs.Remove("SmtpDetails") 'Remove, if, already exists. Then add
        Starter.kvs.PutEncrypted("SmtpDetails",Starter.MapSmtpDtls,"MyPassword")
    Else
        Starter.kvs.PutEncrypted("SmtpDetails",Starter.MapSmtpDtls,"MyPassword")
    End If
  • OR Can I directly update the store without deleting the Key first ? Will this method update the value of the existing key ?
  1. Can I store a Boolean Value in KeyValueStore ?
  • If yes, then is the following the right way to do it
    B4X:
    Dim IsAutoLogin as Boolean
    IsAutoLogin = True
    kvs.PutSimple("AutoLogin",IsAutoLogin)
Regards

Anser
 
Last edited:

tufanv

Expert
Licensed User
Longtime User
Hello,

You can use put for the existing one. It will update the old entry. You dont need to delete and add each time.
I never tried if it stores boolean but it take 2 min to try it. You can try it and see.


Hi,

  1. I would like to know the best way OR the expected way to update the VALUE of an already existing KEY in KeyValueStore database.

  • Should I delete the Key and its value first and then Create a new Key and the New Value using kvs.putsimple / kvs.PutEncrypted ?
  • For eg.
    B4X:
    If Starter.kvs.ContainsKey("SmtpDetails") Then
        Starter.kvs.Remove("SmtpDetails") 'Remove, if, already exists. Then add
        Starter.kvs.PutEncrypted("SmtpDetails",Starter.MapSmtpDtls,"MyPassword")
    Else
        Starter.kvs.PutEncrypted("SmtpDetails",Starter.MapSmtpDtls,"MyPassword")
    End If
  • OR Can I directly update the store without deleting the Key first ? Will this method update the value of the existing key ?
  1. Can I store a Boolean Value in KeyValueStore ?
  • If yes, then is the following the right way to do it
    B4X:
    Dim IsAutoLogin as Boolean
    IsAutoLogin = True
    kvs.PutSimple("AutoLogin",IsAutoLogin)
Regards

Anser
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Sorry. Its my mistake.

In the question that I used in the post #1 of this thread, I have used kvs.PutSimple("AutoLogin",IsAutoLogin).

In my App I am using kvs.Put("AutoLogin", AutoLogin )
 
Upvote 0
Top