Android Question Passing values between activities

davepamn

Active Member
Licensed User
Longtime User
How do I create a singleton to pass values from one activity form to another
 
You do not need to create a singleton for that. You can use Process_Global variables to share data or better use CallSubDelayed.

Public sGlobalFactory as string

This variable does not seem to be visible in the second activity. Did I declare the variable properly?
 
Upvote 0
Parsing code. Error
Error parsing program.
Error description: Undeclared variable 'sglobalfactory' is used before it was assigned any value.
 
Upvote 0
Sub cmdEnter_Down
StartActivity(frmSetup)
CallSubDelayed2(frmSetup,"SetFactory",sGlobalFactory)
End Sub


'******in frmSetup

Sub SetFactory(sValue As String)
sCurrentFactory=sValue
End Sub

The process seems difficult

Is there a better way?
 
Upvote 0
I use this thenic:
Create a PUBLIC VAR in Process_Global (frmUsuario activity sample)
B4X: Copy
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Type TD_Usuario(Codigo As Int, Nombre As String, Clave As String)
    Public AccionEnForm As String
End Sub

and in other activity, BEFORE CALL THIS activity somethink like this:


B4X: Copy
    frmUsuario.AccionEnForm = "SetUsuario"
    StartActivity(frmUsuario)

And use this public var in frmUsuario activity.

You can returns values as this thecnic.
Be carefour with this PUBLIC var between other calls.
ALWAYS put somenthig in other calls to this Activity

B4X: Copy
    frmUsuario.AccionEnForm = "nothingtodo"
    StartActivity(frmUsuario)
 
Upvote 0
Back
Top