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

Alphaw

Member
Licensed User
Longtime 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.
 

Roycefer

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

Alphaw

Member
Licensed User
Longtime User
Thank you Roycefer. I solve the problem. Thank you again.

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.
 
Upvote 0

jai76

Member
Licensed User
Longtime 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
 
Upvote 0

Alphaw

Member
Licensed User
Longtime 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

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.
 
Upvote 0
Top