Android Question StateManager - error - can't save app

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

I started to use the StateManager. After downloading it and unzipping it, I copied StateManager.bas into my project where the other .bas files were located. I added it into the project as an existing module and it showed up as a tab so I could see the coding of the module. When I tried to save the project I got an error on the If statement. Is this module incomplete?

This is the If statement that gave the error:

B4X:
If Settings.IsInitialized = False Then

This is the Sub that has the If statement:

B4X:
Sub GetSetting2(Key As String, DefaultValue As String)
    If Settings.IsInitialized = False Then
        'load the stored settings
        If File.Exists(File.DirInternal, settingsFileName) Then
            Settings = File.ReadMap(File.DirInternal, settingsFileName)
        Else
            Return DefaultValue
        End If
    End If
    Dim v As String
    v = Settings.GetDefault(Key.ToLowerCase, DefaultValue)
    Return v
End Sub
 

sorex

Expert
Licensed User
Longtime User
I think you're confusing things or atleast I used it totally different than you did, here's an example...

B4X:
StateManager.loadStateFile 'load
setting1=StateManager.GetSetting2("setting1","0") 'get

StateManager.SetSetting("setting1",setting1+1) 'set
StateManager.SaveSettings 'save
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi sorex,

Actually, all I did was to copy and install the StateManager.bas code module and not use it yet.

Usually when I add a code module to my project I do a ctrl-s to save the project. That's when the error popped up. It popped up in the code module. Once I can get the code module saved then I will try to use it. Looks like there may be something missing from the coding of the StateManager.bas code module.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
did you add the randomaccessfile library?

my b4a file shows these libs in use

Library1=core
Library2=phone
Library3=randomaccessfile
Library4=reflection
Library5=stringutils


but core is default, phone not needed. not sure about the other 3
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
here's the one I use(d)
 

Attachments

  • StateManager.zip
    1.9 KB · Views: 161
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Here is a file showing the error I get when trying to save the app.

StateManager error.png
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
I created a copy of the Map called Settings to SettingsEmad and renamed all of the references to Settings. to SettingsEmad. and the app saved ok.

Now I will try to see if I can use the module. Maybe "Settings" is a reserved word and can't be used as a Map.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Did the StateManager get changed slightly? I'm using v1.01 and settings is in lowercase...?

ETA : Nope, that doesn't seem to be the problem - are you sure you haven't edited the bas file incorrectly in some way? I would suspect that something else, elsewhere is generating this error for you.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
What happens if you comment out that If Statement and the End if, will it save then?

I got an error from here.

B4X:
Sub GetSetting(Key As String)
    Return GetSetting2(Key, "")
End Sub

I did get it to compile and run by adding a new map called SettingsEmad and changed all of the parts of the module that used to have Settings and even got a "False" when I ran this code from my "Main" module:

B4X:
    Msgbox(StateManager.RestoreState(Activity, "Main", 60),"")

So maybe that Setting keyword was a reserved word.
 
Upvote 0
Top