Public Class in Process_Global, reference from another activity

aalekizoglou

Member
Licensed User
Longtime User
Suppose we have the following code:

B4X:
'Activity A

Sub Process_Globals
 Public ThisIsAPublicVariable As String
 Public ThisIsAPublicClass As SomeClass
End Sub

Sub Activity_Create(FirstTime As Boolean)
   ThisIsAPublicClass.Initialize("")
   'Initialize the class and set properly
   startactivity(activityb)
End Sub


'Activity B
Sub Activity_Create(FirstTime As Boolean)
   log(activitya.ThisIsAPublicVariable)
   log(activitya.ThisIsAPublicClass)
End Sub

Sub SomeFunction
  'Work with activitya.ThisIsAPublicClass
End Sub

In ActivityA an instance of SomeClass is created in Process_Globals, and settled properly. Then it calls ActivityB where the same instance from ActivityA is used. My question is will the activitya.ThisIsAPublicClass class always be in memory since the relevant activity is paused? What happens if the class is really memory intensive with Lists and Maps?

If that handle is not safe, is there any other safer way to use the same instance from two activities?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
What happens if the class is really memory intensive with Lists and Maps?
How large are the lists and maps? Assuming that they do not hold bitmaps then they probably shouldn't be considered memory intensive.

Process global variables are always in memory. It doesn't matter where they are declared.
 
Upvote 0
Top