greenpepper7
New Member
I've been playing around with classes and looking at the java underneath that's actually running it all. I have a simple project with the Main activity, and one standard b4x class (cls1) that contains the following code:
cls1 is instantiated in Main:
When B4A converts this code in main to java we get
_cls._initialize() then goes on to call innerInitialize() which does some stuff then loads the class globals.
Now, if I remove the view1 variable from cls1 so that class_globals is now empty, the java code changes to
If I understand correctly, removing the reference to the view from cls1 means cls1 is no longer an activity object. It doesn't need to be tied to the lifecycle of an activity and will no longer cause a memory leak if it was defined in main's process_globals.
However, why has the ba object passed to _initialize() changed from an activity BA to a process BA? From what I have seen in the past, the BA object is used for things like raising and waiting for events and doesn't have anything to do with ui elements. Does the class need different types of context (activity or non-activity) based on whether or not it is an "activity object"?
Additionally, if I was to manually call _initialize() on cls1 when it was an activity object, what would happen if I manually passed processBA instead of mostCurrent.activityBA? Would cls1 and view1 still function correctly?
cls1:
Sub Class_Globals
Private view1 As View
End Sub
Public Sub Initialize
End Sub
main:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
Dim cls As cls1
cls.Initialize
End Sub
When B4A converts this code in main to java we get
Java:
b4a.example.cls1 _cls = null;
_cls = new b4a.example.cls1();
_cls._initialize(mostCurrent.activityBA);
Now, if I remove the view1 variable from cls1 so that class_globals is now empty, the java code changes to
Java:
b4a.example.cls1 _cls = null;
_cls = new b4a.example.cls1();
_cls._initialize(processBA); // Now uses process BA instead of activity BA
However, why has the ba object passed to _initialize() changed from an activity BA to a process BA? From what I have seen in the past, the BA object is used for things like raising and waiting for events and doesn't have anything to do with ui elements. Does the class need different types of context (activity or non-activity) based on whether or not it is an "activity object"?
Additionally, if I was to manually call _initialize() on cls1 when it was an activity object, what would happen if I manually passed processBA instead of mostCurrent.activityBA? Would cls1 and view1 still function correctly?