Android Question B4A Global Variables Problem?

ronovar

Active Member
Licensed User
Longtime User
Hi.. i im using this code and global variable is not set where i im doing wrong?

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim XBMC(20) As String
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("Layout1")
'GET - encrypted data
GetEncrypted

Log(XBMC(0))
End Sub

Sub GetEncrypted
'DECLARE - variables
Dim Job0 As HttpJob
'INITIALIZE - variables
Job0.Initialize("Job0", Me)
'GET - encrypted
Job0.Download("http://myurl.com/dejavu/")
End Sub

Sub JobDone(Job As HttpJob)
'DECLARE - variables
Dim JSON As JSONParser
'CHECK - job
If Job.Success = True Then
'SELECT - job
Select Job.JobName
Case "Job0"
'INITIALIZE - json
XBMC(0) = "okkkkkkooooo"
End Select
End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


When i use Log(XBMC(0)) it is empty in log viewer in B4A....i don't know why variable that is defined as global it does not hold value assigned in Job0 Case...is this a bug in B4A or what i im doing wrong?

How to define global variable and get access to this global variable in all modules....for example this is Main module.

Thanks
 

JonPM

Well-Known Member
Licensed User
Longtime User
This is likely because the JobDone hasn't been completed by the time you log the variable.

Generally it is best to place global variables in the Starter service as this module isn't paused and can be accessed across all modules.
 
Upvote 0
Top