saving counter variables using StateManager

IanMc

Well-Known Member
Licensed User
Longtime User
Am I doing something wrong here? its' not working, keeps logging timesRun as 1

(this code is in Main Sub Activity_Create)
B4X:
If FirstTime = True Then   
   Dim tr As Int      
   If StateManager.GetSetting("timesRun") <> "" Then
      tr = StateManager.GetSetting("timesRun")      
      tr = tr + 1
   Else 
      tr = 1
   End If
   StateManager.SetSetting("timesRun", tr)
   Log("Times Run " & tr)      
End If

It's me, it must be me :)
 

mc73

Well-Known Member
Licensed User
Longtime User
You should use stateManager.saveSettings after the setSetting, otherwise the map is not written to the settingsFile.
 
Upvote 0

IanMc

Well-Known Member
Licensed User
Longtime User
Ah yes of course! Thanks mc!
Although I use Statemanager.Savesettings elsewhere i can't just presume it gets called after this.
That must be the answer! I'll check.

Cheers!

You know I might just put a call to SaveSettings in the SetSettings subroutine. It won't catch me out again that way :)

Hey this is my 100th post and I got a new star! Yay! :icon_clap:
 
Last edited:
Upvote 0
Top