Android Tutorial KeyValueStore class - Simple and efficient key/value data store

Status
Not open for further replies.

alhaim

Member
Licensed User
Longtime User
Why after 15 minutes on my Samsung Galaxy Tab, and after only 15 seconds on my IDEOS android phone, does the data stored with keyvaluestore disappear? Is there some code I am missing? What do I have to change in the code to make a permanent save? Thanks.
 
Last edited:

RonC.

Member
Licensed User
Longtime User
Tried to use Keystore, but it's as if Basic4Android doesn't see the Type and I'm not sure why... Your example works great, but when I even try to copy over the first line into a new program it displays in red... I used the Core, SQL, and RandomAccessFile Libraries... What am I forgetting or doing wrong?

Note: When I attempted to zip and attach the file to the forum (from within Basic4Android) I got the error: "An Error occurred. Could not find a part of the path 'C:\Users\rcotton\Documents\My Basic4Android\KeyStoreValue\Objects"
 

Attachments

  • KeyValueStoreProblem.png
    110.8 KB · Views: 351
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
how can i get only
only Item #1 in string?
lala = Item #1 ?
(ArrayList) [Item #1, Item #2, Item #3, Item #4, Item #5]
 

driesvp

Member
Licensed User
Longtime User
Strange thing: when putting and reading a value to KVS it's possible to recall it from the same app but not from another app. I tought it was put on the external store so it would be accessible from all apps?

first app
B4X:
    kvs.Initialize(File.DirDefaultExternal, "Versions")

    msgbox(kvs.GetSimple("ipadres"),"") ' the value was stored in this app

second app:

B4X:
    kvs2.Initialize(File.DirDefaultExternal, "Versions")
    Msgbox(kvs2.GetSimple("ipadres"),"")
 

alexwekell

Member
Licensed User
Longtime User
Android L seems to have broken this?

I used to have a simple implementation:

B4X:
kvs.Initialize(File.DirDefaultExternal,"datastore")

And this is the code I've narrowed it down to. When I comment this out, my app starts correctly (though it doesn't work)

I keep getting nosuchfield errors...

B4X:
LogCat connected to: 03fbf34c093c82f9
--------- beginning of crash


Fatal signal 6 (SIGABRT), code -6 in tid 28638 (AsyncTask #1)
Fatal signal 6 (SIGABRT), code -6 in tid 28732 (AsyncTask #1)
Fatal signal 11 (SIGSEGV), code 1, fault addr 0xb51bd21a in tid 20187 (Binder_1)
--------- beginning of events
--------- beginning of system


Data connection inactive timestamp 27942082 is before start time 21422376000
Data connection inactive timestamp 27960692 is before start time 21422376000
Data connection inactive timestamp 27965912 is before start time 21422376000
Data connection inactive timestamp 28049982 is before start time 21422376000
Data connection inactive timestamp 28058772 is before start time 21422376000
Data connection inactive timestamp 28070822 is before start time 21422376000
Data connection inactive timestamp 28076095 is before start time 21422376000
Data connection inactive timestamp 28108352 is before start time 21422376000
Data connection inactive timestamp 28164212 is before start time 21422376000


Starting service ServiceState{17c27b92 com.qualcomm.qcrilmsgtunnel.QcrilMsgTunnelService pkg=com.qualcomm.qcrilmsgtunnel proc=17c27b92} without owner
Starting service ServiceState{3940baba com.google.android.tts.service.GoogleTTSService pkg=com.google.android.tts proc=3940baba} without owner
Starting service ServiceState{17c27b92 com.qualcomm.qcrilmsgtunnel.QcrilMsgTunnelService pkg=com.qualcomm.qcrilmsgtunnel proc=17c27b92} without owner
Data connection inactive timestamp 28428512 is before start time 21422376000
--------- beginning of main


** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = true **
java.lang.RuntimeException: java.lang.NoSuchFieldException: mostCurrent
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:955)
    at android.os.Handler.handleCallback(Handler.java:738)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5070)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
Caused by: java.lang.NoSuchFieldException: mostCurrent
    at java.lang.Class.getDeclaredField(Class.java:886)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:914)
    ... 8 more
dns64_detection/no dns64, giving up
Data connection inactive timestamp 28851542 is before start time 21422376000
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
java.lang.RuntimeException: java.lang.NoSuchFieldException: mostCurrent
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:955)
    at android.os.Handler.handleCallback(Handler.java:738)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5070)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
Caused by: java.lang.NoSuchFieldException: mostCurrent
    at java.lang.Class.getDeclaredField(Class.java:886)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:914)
    ... 8 more
dns64_detection/no dns64, giving up
Data connection inactive timestamp 28918522 is before start time 21422376000
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
java.lang.RuntimeException: java.lang.NoSuchFieldException: mostCurrent
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:955)
    at android.os.Handler.handleCallback(Handler.java:738)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5070)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
Caused by: java.lang.NoSuchFieldException: mostCurrent
    at java.lang.Class.getDeclaredField(Class.java:886)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:914)
    ... 8 more
dns64_detection/no dns64, giving up
Data connection inactive timestamp 28974532 is before start time 21422376000
** Activity (main) Create, isFirst = true **


** Activity (main) Resume **


** Activity (main) Pause, UserClosed = true **


java.lang.RuntimeException: java.lang.NoSuchFieldException: mostCurrent


    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:955)
    at android.os.Handler.handleCallback(Handler.java:738)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5070)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
Caused by: java.lang.NoSuchFieldException: mostCurrent
    at java.lang.Class.getDeclaredField(Class.java:886)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:914)
    ... 8 more
 

alexwekell

Member
Licensed User
Longtime User
I tested it on the emulator. There were some issues with the rapid debugger. However once these issues were fixed the KeyValueStore example worked correctly in both debug and release modes.

Did you encounter similar issues with other projects?

This is the only project I use it in
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel how can i create a new key?

Private Sub CreateTable
sql1.ExecNonQuery("CREATE TABLE IF NOT EXISTS main(key TEXT PRIMARY KEY, value NONE)")
End Sub


for example
sql1.ExecNonQuery("CREATE TABLE IF NOT EXISTS main(key TEXT PRIMARY KEY, index BIGINT, value NONE)")

?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…