Android Question connecting activity modules help

piero123

Member
Licensed User
Longtime User
hi everyone , i have activity modules, in the activity module 1 i have this code
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
  
    If FirstTime Then
SMTP.Initialize("smtp.gmail.com", 465, "[email protected]", "jaja1234", "SMTP")
SMTP.UseSSL = True 'Esta linea la ponemos ya que Gmail requiere SSL
SMTP.Subject = (EditText2.Text)
SMTP.HtmlBody = True
End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
SMTP.Body = EditText1.Text
SMTP.To.Add(EditText6.Text)
SMTP.Send
  End Sub

Sub SMTP_MessageSent(Success As Boolean)
  If Success=True Then StatusSend1="SI enviado"
  If Success=False Then StatusSend1="NO Enviado"
  Log(StatusSend1)
End Sub

Sub Button2_Click
  
Activity.LoadLayout("2")
  
End Sub

and in the activity module 2 i have this code


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private EditText5 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout2")

End Sub

Sub Activity_Resume

End Sub



Sub Activity_Pause (UserClosed As Boolean)

End Sub

my question is , how i can do to the activity module 1 recognize the editext5 what is in the activity module 2 sorry for my bad english
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
From activity 2, on change or in Activity_Pause, I would store the content of the edittext5 in a file using Erel's PreferrenceActivity library for easiness. And retrieve its content from activity 1.

Save content sample
B4X:
Dim Manager as PreferenceManager
Manager.SetString("AnyName",edittext5.text)

Read sample
B4X:
Dim Manager as PreferenceManager
Edittext5.text=Manager.getstring("AnyName")
 
Last edited:
Upvote 0

piero123

Member
Licensed User
Longtime User
can u see my project i dont understand :( i want edittext not delete the text i write sorry for my bad english
 

Attachments

  • help.zip
    7.9 KB · Views: 148
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I would help you but I can not load your project, it is for the new B4A version.

But I would advise you to give to views a self-explanatory name (you could use edtMsgBody or edtBody instead of EditText1.Text) and to explain what the second activity does.

However, you can use a variable declared in Process_Globals and fill it with the contents of EditText5, then every activity can read (and write) that variable, using Activity2.VarName

(sorry but my English is bad too :))
 
Last edited:
Upvote 0

piero123

Member
Licensed User
Longtime User
i only i want is the editext3 dont delete the text what i write , because every i change the layout the edittext3 delete the text and is empy :/
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

piero123

Member
Licensed User
Longtime User
i try that but nothing :/ can u check my project? i only want is the editext3 dont delete the text i write cuz every i change the layout and i return the edittext is empy :/ please help :(
 

Attachments

  • help.zip
    7.9 KB · Views: 139
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

piero123

Member
Licensed User
Longtime User
i use that and dont work :/ , i change my project this is the code

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Private Button2 As Button
    Private EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Button1_Click
    removeview
    Activity.LoadLayout("2")
End Sub
Sub removeview
Dim i As Int
For i=Activity.NumberOfViews-1 To 0 Step -1
Activity.RemoveViewAt(i)
Next
End Sub
Sub Button2_Click
    removeview
    Activity.LoadLayout("1")
End Sub

i only want all i write in the edittext1 dont delete everytime i change the layout , here is my project please check :( im really confused
 

Attachments

  • hellp.zip
    7.9 KB · Views: 145
Upvote 0

klaus

Expert
Licensed User
Longtime User
In your first post you are speaking about two Activities !
But in your example code there is only one !?
This code works :
B4X:
Sub Process_Globals
    Dim EditText_Text = "" As String
End Sub

Sub Globals
    Dim Button1 As Button
    Dim Button2 As Button
    Dim EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Button1_Click
    removeview
    Activity.LoadLayout("2")
    EditText1.Text = EditText_Text
End Sub

Sub removeview
    Activity.RemoveAllViews
End Sub

Sub Button2_Click
    removeview
    EditText_Text = EditText1.Text
    Activity.LoadLayout("1")
End Sub
But if you use another Activity for layout '2' you should use margret's proposal.
 
Upvote 0
Top