Is there a way to restore the already entered text of an input dialog, if the user switches to another app and then returns to my app?
B4X:
Dim id As InputDialog
Dim sf As Object = id.ShowAsync("", "Enter your name", "Ok", "", "Cancel", Null, False)
Wait For (sf) Dialog_Result(Result As Int)
Log(id.Input)
When I switch to the home screen or another app while the input dialog is shown, the result code is never called and thus I cannot store the input text in a global variable. When I return to the app, the dialog is closed and the already entered text is lost. Is there a solution to this problem?
At first glance, I don't see a solution; I might think about creating a new dialog in the Activity's Resume event (saving the user's text in a KVS2, in the Pause event), but I don't like that at all.
I haven't used non-B4XPages app for a while but I tested this using B4A default.
The idea is to use a timer to check the contents of the embedded textview.
You will need to store 'savedInput' in an file you can read when Activity is resumed.
(The frequency of timer ticks can be less the 10 per second.)
B4X:
Sub Process_Globals
Private xui As XUI
Private checkInput As Timer
Private savedInput As String
End Sub
Sub Globals
Private dialog As B4XDialog
Private input As B4XInputTemplate
Private Panel1 As Panel
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
dialog.Initialize(Panel1)
checkInput.Initialize("saveInput", 100)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
input.Initialize
input.lblTitle.Text = "Enter your name:"
checkInput.Enabled = True
Wait For (dialog.ShowTemplate(input, "OK", "", "CANCEL")) Complete (Result As Int)
checkInput.Enabled = False
If Result = xui.DialogResponse_Positive Then
Dim res As String = input.Text
Log(res)
End If
End Sub
Private Sub saveInput_Tick
Dim inputBase As B4XView = dialog.Base.GetView(2)
Dim txt As String = inputBase.getView(1).text
If txt <> savedInput Then
Log(txt) 'shows input on the fly
savedInput = txt
End If
End Sub