Android Question State Manager


Active Member
Licensed User
Hi masters... Why does state manager dont save sa text of button also does the state manager support sa items in listview? (save sa state of listview with items loaded)

Here is my code

Sub Globals
    Dim Button1 As Button, Label1 As Label, EditText1 As EditText, ListView1 As ListView
    Dim TestInt As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.AddMenuItem("Test Value", "mnuTest")
    If StateManager.RestoreState(Activity, "Main", 0) = False Then
    End If
    Dim AutoUpdate As Boolean
    AutoUpdate = StateManager.GetSetting2("AutoUpdate", False)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        StateManager.SaveState(Activity, "Main")
    End If
End Sub

Sub mnuTest_Click
    Msgbox(TestInt, "")
End Sub

Sub Button1_Click
    Button1.Text = Rnd(1, 101)
    TestInt = EditText1.Text
    For x = 1 To TestInt
    StateManager.SaveState(Activity, "Main")
End Sub



Licensed User
Why does state manager dont save sa text of button
What is "sa text"?
does the state manager support sa items in listview
What is/are sa items?

See code from Stetmanager
Sub SaveState(Activity As Activity, ActivityName As String)
    If states.IsInitialized = False Then states.Initialize
    Dim list1 As List
    For i = 0 To Activity.NumberOfViews - 1
        innerSaveState(Activity.GetView(i), list1)
    states.Put(ActivityName.ToLowerCase, list1)
End Sub
Sub writeStateToFile
    Dim raf As RandomAccessFile
    raf.Initialize(File.DirInternal, statesFileName, False)
    raf.WriteObject(states, True, raf.CurrentPosition)
End Sub
Sub innerSaveState(v As View, list1 As List)
    Dim data() As Object
    If v Is EditText Then
        Dim edit As EditText
        edit = v
        data = Array As Object(edit.Text, edit.SelectionStart)
    Else If v Is Spinner Then
        Dim spinner1 As Spinner
        spinner1 = v
        data = Array As Object(spinner1.SelectedIndex)
    Else If v Is CheckBox Then
        Dim check As CheckBox
        check = v
        data = Array As Object(check.Checked)
    Else If v Is RadioButton Then
        Dim radio As RadioButton
        radio = v
        data = Array As Object(radio.Checked)   
    Else If v Is ToggleButton Then
        Dim toggle As ToggleButton
        toggle = v
        data = Array As Object(toggle.Checked)
    Else If v Is SeekBar Then
        Dim seek As SeekBar
        seek = v
        data = Array As Object(seek.Value)
    Else If v Is TabHost Then
        Dim th As TabHost
        th = v
        data = Array As Object(th.CurrentTab)
        For i = 0 To th.TabCount - 1
            th.CurrentTab = i
        Dim data() As Object
        Dim r As Reflector
        r.Target = th
        Dim tabParentPanel As Panel
        tabParentPanel = r.RunMethod("getTabContentView")
        For i = 0 To tabParentPanel.NumberOfViews - 1
            innerSaveState(tabParentPanel.GetView(i), list1)
    Else If v Is ScrollView Then
        Dim sv As ScrollView
        sv = v
        data = Array As Object(sv.ScrollPosition)
        Dim data() As Object
        innerSaveState(sv.Panel, list1)
    Else If v Is Panel Then
        Dim panel1 As Panel
        panel1 = v
        For i = 0 To panel1.NumberOfViews - 1
            innerSaveState(panel1.GetView(i), list1)
    End If
    If data.Length > 0 Then list1.Add(data)
End Sub
There is no Button-support in it. Also there is no listview support.

If you want to store the text of a button or th content of a listview then you need to create a object which hold the listview items (listview does not expose such list) and you need to extend the class to write (or later restore) your own itemlist.

As for the button. You need to extend the class too to support button text


Active Member
Licensed User
Also can the statemanager save my global variables cause if the phone change orientation the grobal variable also has been reset...