Android Question [solved] StateManager for Checkbox?

anOparator

Active Member
Licensed User
Longtime User
Am using 2 activities.

1: An intro activity with a "Do not show this page again" Checkbox that shows until clicking the Checkbox.

2: Main activity which shows first once CheckBox is checked.

My main issue was with the SetSettings/SaveSettings and GetSettings statements. Then I read about RestoreState.

Now I understand StateManager less. ( or is it CheckBox being a special type of button?).

The attached .zip is just trying to get CheckBox state when screen rotates but SaveSettings with 2 activities us what I'm working on.

Thanks in advance.
 

DonManfred

Expert
Licensed User
Longtime User
What is the question?
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
how to have an Intro activity with a CheckBox, after CheckBox is checked only the Main activitiy shows when launching the app.

Hoping I wrote this well.
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
you wil have to save the a value, like ShowSplashScreen. You can do this for example with the statemanager or keyvaluestore will be an other possibility. The statemanger can save the state of UI-Elements or something else (String-String-pairs). In your case you need to save a value and not the checkbox UI-state! something like:
B4X:
    StateManager.setSetting("showSplashScreen", "yes")
    StateManager.SaveSettings
    ...
    Dim state As String = StateManager.GetSetting("showSplashScreen")
    If state = "yes" Then
        'show activity splash
    End If
 
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
I have used keyValueStore to create/confirm/store passwords, and thought StateManager was recommended for tracking a UI state.

Is your Set/Save is in Activity_Pause is GetSettings in 'Sub CheckBox_CheckedChange'?

Thanks for the pointer, will try tomorrow.
 
Last edited:
Upvote 0

anOparator

Active Member
Licensed User
Longtime User
:)
B4X:
 Sub Activity_Create (FirstTime As Boolean)
activity.loadLayout("Layout1")
StateManager.RestoreState(Activity, "Main", 60)
If Checkbox1.Checked = False Then
   StartActivity(" Main")
Else
    StartActivity("SecondActivity")
End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   StateManager.SaveState(Activity, "Main")
    StateManager.SaveSettings
If Checkbox 1.Checked = True Then
    Activity.Finish
End If
End Sub

I'm starting to enjoy this B4a
it's basically clean code.
 
Last edited:
Upvote 0
Top