Android Question Shutting tablet does not destroy state or clear app

Steve Miller

Active Member
Licensed User
Longtime User
My app has 11 tabs on it. I set an image on the tab as the user progresses through the app. The problem I am seeing is when the tablet is shutdown, it doesn't appear to reset the app. It continues where it left off. The tabs still have their images on them and textboxes are filled in. I'd like it to start the app fresh when turned the tablet is restarted, wiping any previous entries.

This is my Activity_Pause procedure.

B4X:
Sub Activity_Pause (Finishing As Boolean)
   
    Try
        If kiosk Then StartServiceAt(KioskService, DateTime.Now + 1 * DateTime.TicksPerSecond, False)       
        If Finishing Then
            StateManager.ResetState("Main")
        Else
            StateManager.SaveState(Activity, "Main")
        End If
        StateManager.SaveSettings
       
    Catch
        Ex = LastException
        cErrorLog.InsertLog(3,"CustomerTablet.Main.Activity_Pause",Ex.Message)
        If DebugMode Then
            Log(Ex.StackTraceElement(0))
        End If
    End Try
End Sub
 

Reviewnow

Active Member
Licensed User
Longtime User
I don't know how users leave your application but something like this should work

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event

If KeyCode = KeyCodes.KEYCODE_BACK OR KeyCode = KeyCodes.KEYCODE_HOME Then
    If Msgbox2("are you sure you want to exit the application", "", "Yes", "Cancel", "", Null) = DialogResponse.POSITIVE Then

 
StateManager.DeleteStateAndSettings
Activity.Finish
    Else
        Return True
    End If
End If

End Sub
 
Upvote 0

Steve Miller

Active Member
Licensed User
Longtime User
Just tried it but didn't work.
What I am doing is working my way through a few tabs and then powering off the tablet. When I power it back up, and the app starts, it continues where it left off. The data is still there.
 
Upvote 0

Reviewnow

Active Member
Licensed User
Longtime User
if you want it to remove every time it starts up

B4X:
Sub Activity_Create(FirstTime As Boolean)

if FirstTime then
  Statemanager.DeleteStateAndSettings
 
end if

end sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…