Android Question How to use KeyValueStore without cursor?

gacar

Active Member
I am using KeyValueStore without cursor. My application stored some user variables (string and boolean, each 2 seconds). But about 10 minutes later i am getting memory error. How can i override to KeyValueStore or clean memory? Thanks

Code:
Copying updated assets files (20)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
onAuthStateChanged: com.google.firebase.auth.internal.zzn@1cbe0a2
onAuthStateChanged: com.google.firebase.auth.internal.zzn@1cbe0a2
onAuthStateChanged: com.google.firebase.auth.internal.zzn@1cbe0a2
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
..........................................     'There are hundreds more same lines here (** Service (firebasemessaging) Start **)
** Service (firebasemessaging) Start **
** Service (firebasemessaging) Start **
Error occurred on line: 24 (KeyValueStore)
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. 
    at android.database.CursorWindow.<init>(CursorWindow.java:108)
    at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:138)
    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
    at anywheresoftware.b4a.sql.SQL$CursorWrapper.getRowCount(SQL.java:335)
    at anywheresoftware.b4a.sql.SQL$ResultSetWrapper.NextRow(SQL.java:457)
    at DemirHaber.Mobile.keyvaluestore._get(keyvaluestore.java:83)
    at DemirHaber.Mobile.b4xpagesohbet._verioku(b4xpagesohbet.java:235)
    at DemirHaber.Mobile.b4xpagesohbet._girisekraniacik(b4xpagesohbet.java:764)
    at DemirHaber.Mobile.b4xpagesohbet._giriskontrol(b4xpagesohbet.java:787)
    at DemirHaber.Mobile.b4xpagesohbet._sql_ready(b4xpagesohbet.java:948)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6161)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:892)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
** Activity (main) Pause event (activity is not paused). **
 
Your other post on this topic said that you had collected 2 Mbytes of data in ten minutes. It did not say if you expected to continue amassing data at that rate.

A KVS is intended, typically, to store app preferences or state variables and similar low amounts of data, not high volume data. You need to choose the right tool for the job that you want to do.
 
Upvote 0
Your other post on this topic said that you had collected 2 Mbytes of data in ten minutes. It did not say if you expected to continue amassing data at that rate.

A KVS is intended, typically, to store app preferences or state variables and similar low amounts of data, not high volume data. You need to choose the right tool for the job that you want to do.

Thank you for reply. Do you know any alternative tool?
 
Upvote 0
It is difficult to suggest a solution without having a specification. Looking again at your earlier post ...

1. You are writing data such as "UserOnline = TRUE" every two seconds.
2. You are getting the "Cursor window allocation of 2048 kb failed" after ten minutes.
3. Your log shows that you are getting the message "** Service (firebasemessaging) Start **" several hundred times.

It is difficult to see how key/values like item (1) can produce cursor sizes exceeding 2Mb, although I know nothing about how KVS works internally. My suspicions are that you have a coding error, as suggested by item (3). Try understanding that and you might find that a KVS will work after all.
 
Upvote 0
Back
Top