It will be great if anyone can put up some samples showing how to save and load settings of a widget. Settings like background color, opacity,text color,text size and also save and load spinner state...etc. As such samples will be a great help for many of us here who are new to B4a and even programming(i am new to programming).
I have a widget with a label which displays some information from datatbase and the information have two versions say A and B and user can select the version from activity module. If i have a spinner in activity module with 2 options say A and B and say user selects the option B and the setting is saved using statemanager. but how can i retrieve the same setting using statemanger in service module so that the version B is displayed in the widget.
To get a Setting with StateManager, you simply have to call:
B4X:
Dim manager As PreferenceManager
manager.GetString("YourSetting")
manager.GetBoolean("YourBooleanSetting")
You have have A_ and B_ for each of your settings. However, it was 3 days ago I struggled with this and for me the easiest solution was to store my setting in the database(I have two layouts too). Then, I wrote a class tStyle which consists of the current loaded style. My entire logic doesn't care which style is created but simply gets the settings from the loaded data.
If you store simple data types(string, int), you may find it fair enough to use the preference manager. But according to my opinion, provided that you have multiple options(now they are 2 but you can change that in a future version), consider using an advanced more flexible approach like databases.