Android Question Save/Restore state of TabHost

Frank Cazabon

Member
Licensed User
Longtime User
I am trying to use the StateManager library to save & restore the state of my application which has one activity and a tabhost with 4 tabs. The problem is that the tab that was active at the time of an orientation change is not restored.

Some code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    If StateManager.RestoreState(Activity, "Main", 60) = False Then
        'set the default values
'        EditText1.Text = "Default text"
'        EditText2.Text = "Default text"
    End If
   
    Activity.LoadLayout("MainMenu")

    tbhMain.AddTab("Select Route","SelectRoute")
    tbhMain.AddTab("Load","Load")
    tbhMain.AddTab("Deliver","Deliver")
    tbhMain.AddTab("Upload","Upload")

End Sub

Sub Activity_Resume
    StateManager.ResetState("Main")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed Then
        StateManager.ResetState("Main")

    Else
        StateManager.SaveState(Activity, "Main")
    End If
    StateManager.SaveSettings
End Sub

Is there something I am missing?
 

Frank Cazabon

Member
Licensed User
Longtime User
Yes. You need to call StateManager.RestoreState at the end of Activity_Create.
Thanks!

Now that's working, I am not getting the SearchView Lists on some of those tabs to display the list that was displayed prior to the change. Any ideas for that one?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…