Android Question Activities and Variables.

John Sturt

Active Member
Licensed User
Longtime User
Hello I seem to have missed something because this is driving me nuts.

I have two activities and want to pass a string from one to the other.

Essentially i have this:
Activity One

Sub Process+_Globals
Dim Myvalue As String
end Sub
...
Sub Whatever
Start Activity2
end Sub

Activity 2
When i try to assign or even print to the log
all i get is variable undeclareed

Any Help?
 

John Sturt

Active Member
Licensed User
Longtime User
Thank You for your reply but the problem i am having is not a StartActivity it
is a passing Variable problem.

In Activity1 i write
sub process_globals
dim MyValue As String
end Sub

I then go on to call Activity 2
and try to access "MyValue" from within Activity 2
for example
Log (MyValue)

At the debug rapid stage i get the error
Undeclared variable MyValue

Any help?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
John .. Please use [code ] tags when posting code ... easier to read. (see images);)

As Klaus stated , you must reference the activity name where you declared the variable.
you have 2 Activities.. 'Activity1' and 'Activity2'

In Activity1
B4X:
Sub Process_Globals
  Dim MyValue As String = "ABC"
End Sub

Then in Activity2 ..
B4X:
Log (Activity1.MyValue) '...make reference to the activity the variable was dimed.
 

Attachments

  • Code Tags.JPG
    Code Tags.JPG
    13.1 KB · Views: 153
  • Auto Code Tags.JPG
    Auto Code Tags.JPG
    11.5 KB · Views: 140
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Your welcome .. May you B4A experience be long and fruitful ...:)
 
Upvote 0

ELCHARO

Member
Licensed User
Longtime User
HI! I have a problem.

I can access to main.some_variable from a second activity.
I can write main.some_variable=0 from a second activity

But when return to main, i lose this changes.

Why,How, What, can do to mantein this values.

Thanks.
 
Upvote 0
Top