Android Question Using variables in process globals of one activity to another activity

Discussion in 'Android Questions' started by Alphaw, Jul 15, 2015.

  1. Alphaw

    Alphaw Member Licensed User

    I am a new user trying make android apps with B4A, as the title of the question, if I created 2 activities, one is "main" and another is "page 1".

    In "main", I set a variable, Name, and will do several process to change the value of Name, then I would like to show the value of Name in "page 1". However I cannot use the value of Name, and it said "undeclared variable 'Name' is used before it was assigned any value."

    How can I use the value of Name for other activity?

    P.S I only write Dim Name As String at Process Globals of Main but none at Page 1.

    Please help. Thank you.
     
  2. Roycefer

    Roycefer Well-Known Member Licensed User

    Use
    Code:
    Log("Name: " & Main.Name)
    from any activity other than Main.
     
  3. Alphaw

    Alphaw Member Licensed User

    Roycefer,

    May I ask where do I put the code?
     
  4. Roycefer

    Roycefer Well-Known Member Licensed User

    You can use Main.Name anywhere, you don't need to redeclare the Name variable in another module. It will be declared once when the process starts and then be available throughout the lifetime of the process to all activities and services. If you're in Main, though, you don't need to use Main.Name, you can just use Name.
     
  5. Alphaw

    Alphaw Member Licensed User

    Thank you Roycefer. I solve the problem. Thank you again.

     
  6. jai76

    jai76 Member Licensed User

    Dear friend,

    Hope you can share a simple code of you don't mind.
    I unable to link the string from activity2 to activity3

    Thanks in advance
     
  7. klaus

    klaus Expert Licensed User

    Look at chapter 10.5.1 Process variables in the Beginner's Guide.
    In the SourceCode folder of the Beginner's Guide you have an example in the ThreeActivityExample project.
     
  8. Alphaw

    Alphaw Member Licensed User

    Jai76, let's say that in activity 1 named "main" and dim a as int, dim sum1 as int.
    activity 2 named "asd" and dim b as int. sum2 as int.

    If I want to do this: sum1 = a + b
    then I can use this in activity 1: sum1 = a + asd.b

    If I want to do this: sum2 = a + b
    then I can use this in activity 2: sum2 = main.a + b

    You can try it yourself to whether it can work.
     
    Ed Brown likes this.
  9. jai76

    jai76 Member Licensed User

    OK guys, now I understand...
    Thanks you for the explanation.
     
Loading...