Android Question State manager save state togglebutton

angel

Member
Licensed User
Longtime User
Hello

How to save the state of one togglebutton in activity, other components not save

thanks
 

angel

Member
Licensed User
Longtime User
I wanted to use the module "StateManager" to save the state if the application closed, but do not know how to save the state of only one component and not the entire Activity
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,

My little knowledge : for easiness I use Erel's PreferenceActivity library and store the state of the toggle button using a Boolean

B4X:
Sub ToggleButton1_CheckedChange(Checked As Boolean)
    If Checked Then
        Manager.SetBoolean("AC",True)
    Else
        Manager.SetBoolean("AC",False)
    End If
End Sub

You would recall the button's state in Activity_Resume

B4X:
    If Manager.GetBoolean("AC") Then
        ToggleButton1.Checked=True
    Else
        ToggleButton1.Checked=False
    End If
 
Upvote 0
Top