WriteMap

U

unba1300

Guest
Newbie questions here concerning maps...
I want to use a map to store several user settings, which can be changed in more than one place in the app. So if they change one setting, and I then initialize and write that setting to the map, don't all the other settings get erased since I just initialized the map before writing to it?
The way I'm handling it right now is to use a global process variable for each setting and no matter which setting is changed, I write all the setting's current values to the map again, even though only one was changed. Is this a standard approach? Does a map need to be initialized each time before being written to? Thanks.
 

admac231

Active Member
Licensed User
Longtime User
Nope.

Put your declaration and initialisation in process_globals and then you have access to the same map throughout all your activities.

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim myMap As Map
   myMap.Initialize
End Sub

Sub Activity_Resume
myMap.Put("Setting Name","Setting Value")
myMap.Put("Setting Name2","Setting Value2")
myMap.Put("Setting Name3","Setting Value3")
End Sub

Then simply use the myMap.Put whenever you want to change something.
 
Last edited:
Upvote 0
Top