Android Question Transfer the input data

Junctbr

Member
First Activity
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public myVar As String
End Sub

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")  
    myVar = etName.Text
End Sub

Second Activity:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("layout2")
    lblUser.Text = Main.myVar  
    End Sub

The result is ("blank")

I want to display in lblUser.text in 2nd activity the name I input at etName.Text
Thanks in advance for any tips. ^^
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add this sub to the second Activity:
B4X:
Sub StartAndSetText(Text As String)
 lblUser.Text = Text
End Sub

In the first activity use this code to start the second activity instead of StartActivity:
B4X:
CallSubDelayed2(Activity2, "StartAndSetText", "any text you like")

More information:
Using CallSubDelayed to interact between activities and services
 
Upvote 0
Top