Android Question StateManager to save and restore status flags

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

Another newbie question.

I need to save the value of several status flags (INT) but NOT save all flags/settings. Reading through the StateManager tutorial gives me a clue but .... ?

Can someone please tell me if I'm on the right track?

1. Downloaded Erels zip file from the tutorial and added the Module StateManager.bas --- Success

2. Add code:
Sub Activity_Pause (UserClosed As Boolean)
...
StateManager.GetSetting ("Sound_Flag") As String 'Get the current value of Sound_Flag
StateManager.GetSetting ("Beep_Flag") As String 'Get the current value of Beep_Flag
StateManager.GetSetting ("Dollar_Flag") As String 'Get the current value of Dollar_Flag
StateManager.SaveSettings ' Saves the settings above
End Sub


Sub Activity_Create(FirstTime AsBoolean)
...
'Load the previous state
StateManager.SetSetting("Sound_Flag", Value As String) ' Sets Sound_Flag to the saved value
StateManager.SetSetting("Beep_Flag", ????????) ' Sets Beep_Flag to the saved value

StateManager.SetSetting("Dollar_Flag", ????????) ' Dollar_Flag to the saved value

End Sub

Please note the question marks, I have no idea what goes in "Value As String" when the value I need to restore is supposedly stored somewhere.


Thanks in advance

Regards Roger
 

sorex

Expert
Licensed User
Longtime User
you didn't use you variable at all, it should be like this...

and you should set before safe, not get

B4X:
StateManager.SetSetting ("Sound_Flag",Sound_Flag) 'Get the current value of Sound_Flag
StateManager.SetSetting ("Beep_Flag",Beep_Flag) 'Get the current value of Beep_Flag
StateManager.SetSetting ("Dollar_Flag",Dollar_Flag) As String 'Get the current value of Dollar_Flag
StateManager.SaveSettings ' Saves the settings above
End Sub

Sub Activity_Create(FirstTime AsBoolean)
...
StateManager.loadStateFile
Sound_Flag=StateManager.GetSetting2("Sound_Flag", 1) ' Sets Sound_Flag to the saved value
Beelp_Flag=StateManager.GetSetting2("Beep_Flag", 1) ' Sets Beep_Flag to the saved value
Dollar_Flag=StateManager.GetSetting2("Dollar_Flag", 1) ' Dollar_Flag to the saved value


with GetSettings2 you can read it in and if it doesn't exist you can set the default value instead.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Sorex,

Thanks for that. "Set" before "Get" makes sense of the 'Value As String' parameter and clears up the whole thing.
Thank goodness you made better sense of it than me. [Tutorial still reads the other way to me.. go figure.]

Regards Roger.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
You'll get used to it, keep on coding!
Sorex

Sorry to bother you again but I am finally back to the project, -- when I insert the code:

Sub Activity_Pause (UserClosed As Boolean)
TTS1.Release
pw.ReleaseKeepAlive
'MP.Release

StateManager.SetSetting ("vVib_flag",vVib_flag) As String 'Get the current value of vVib_flag
StateManager.SetSetting ("btnClick_flag",btnClick_flag) As String 'Get the current value of btnClick_flag
StateManager.SetSetting ("dollar_flag",dollar_flag) As String 'Get the current value of dollar_flag
StateManager.SetSetting ("sSound_flag",sSound_flag) As String 'Get the current value of sSound_flag
StateManager.SetSetting ("memory1",memory1) As String 'Get the current value of memory1
StateManager.SetSetting ("scrnalive_flag",scrnalive_flag) As String 'Get the current value of scrnalive_flag
StateManager.SaveSettings ' Saves the settings above


End Sub

The lines StateManager.SetSetting ("vVib_flag",vVib_flag) As String etc give me an error that is '=' Expected
I've tried inserting an equals sign in every place I can but it only changes the error.

Any suggestions would be gratefully received.

Regards Roger
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
I never used the As String part, remove it and see what happends.

Did you add the statemanager module to the project?

What's the exact error you get?
 
Upvote 0
Top