localStorage.setItem() not saving on AppStudio 8.5.x

Dear,

When upgrading from 8.4.2 to 8.5.x, the command “localStorage.setItem()” in not saving data, all data are lost when the app is closed totally.

When I upgraded to 8.5.x, my preferences were lost. If you are using Start in Desktop Browser to test, your localstorage loss may be due to the port number setting in preferences was wiped out. I had the same issue and this was my fix. Once the port number is correct, your data “should” reappear, as local storage is organized by port number as well as URI.

Port number is set to ‘0’, same as of the 8.4.2 preferences.
please note that when using “Start in desktop browser” it works fine, but the error appears when uploading an apk made by voltbuilder to an android phone or IOS.

Does the new build have the same certificate as the old one? If not, Android thinks it is a new app.

Nothing changed in the code and certificates between 8.4.2 and 8.5.x , but on the phone when closing the app and reopen it; all configuration (username, password,…) saved and filled during the first run of the app will be lost, you need to refill them, which is not the case in the 8.4.2. builds.

Is this reproducible? Can you give me a step by step?

This isn’t something which AppStudio itself does. I suspect it’s in the sequence of operations that we will see why this happens.

I created an app with 2 inputs (Username and Password) and one Button “Save”, I used “localstorage.setItem()” to save the values of the 2 inputs to memory when clicking the button “Save” in order to use them each time i run the app.

I build the app with “Make Native app with Voltbuilder” on 8.4.2 (or before) and installed it on an android phone; on the first run I enter the 2 values and save them, so each time i run the app everything works fine and both values will be loaded to the inputs using “localstorage.getItem()” .

When building the app with “Make Native app with Voltbuilder” on 8.5.x and installing it to an android phone; on the first run I enter the 2 values and save them, and when rerun the app both values cannot be loaded or does not exist, (like that values are not saved) and the “localstorage.getItem()” did not return any value.

is it clear?

Ah! You’re running as a native app - that changes everything!

Are you doing a debug or release build? Does it ask you to uninstall the old version before installing the new one?

i am doing "emulate android’

No it does not ask to uninstall the old version

Sorry i am doing “run android – debug”

I just did a test here. It worked fine.

Can you send me your little test project?

Dear,

Problem solved following the below:
1- i changed the below Sub to a function
Sub Main()

If localStorage.getItem(“sUsername”) <> null Then
username.value=localStorage.getItem(“sUsername”)
pass.value=localStorage.getItem(“sPassword”)

End If

End Sub

2- I put them in the ‘onshow()’ function.
Function frmMain_onshow()
If localStorage.getItem(“sUsername”) <> null Then
username.value=localStorage.getItem(“sUsername”)
pass.value=localStorage.getItem(“sPassword”)
End If
End Function

In the 8.4.2 the “Sub Main()” will be called when the app run but it did not run in 8.5.x

Thank you for your support

Tip : If you’re pasting code, html or config files, surround the code with triple back ticks (```), before the first line and after the last one. It will be formatted properly.