Attach a demo for my question.
I need return a user definied data from one activity to previous actity.
If the data is primitive (string, int, and other), all is ok, but if my var is definid for me, the value are missing when do a initialize. (i do this for clear var for future calls in other program points)
Code in Main activity
Code in Activity to return a var.
Best view sample.
I need return a user definied data from one activity to previous actity.
If the data is primitive (string, int, and other), all is ok, but if my var is definid for me, the value are missing when do a initialize. (i do this for clear var for future calls in other program points)
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type TD_SAMPLE (Code As Int, Name As String )
Public Rt_Data As TD_SAMPLE
End Sub
Code in Main activity
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private EditText1 As EditText
Private cmdGetData As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
cmdGetData.Text = frmGetData.Rt_Data.Name
EditText1.Text = frmGetData.Rt_Data.Code
cmdGetData.Tag = frmGetData.Rt_Data
'THIS CODE REMOVE THE VALUE INTO TAG. HOW COPY DATA TO TAG? Primitive vars are ok, but user defined data crack.
'i know the cause, but, whats is the best thecnic?
'i do this for clear the var, if i use in other parts of code. but, i do a initialice before call - view: cmdGetData_Click
frmGetData.Rt_Data.Initialize
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub cmdGetData_Click
frmGetData.Rt_Data.Initialize
StartActivity(frmGetData)
End Sub
Sub Button1_Click
Dim V As TD_SAMPLE
Try
v = cmdGetData.Tag
MsgboxAsync (V.Name ,V.Code )
Catch
Log(LastException)
MsgboxAsync ("Error. there are nothing in tag","Error")
End Try
End Sub
Code in Activity to return a var.
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type TD_SAMPLE (Code As Int, Name As String )
Public Rt_Data As TD_SAMPLE
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.
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("Layout")
End Sub
Sub Button1_Click
Rt_Data.Code = DateTime.Now
Rt_Data.Name = "SAMPLE NAME"
Activity.Finish
End Sub
Best view sample.