Hi all!
Erel say that "Android UI elements hold a reference to the parent activity. As the OS is allowed to kill background activities in order to free memory, UI elements cannot be declared as process global variables (these variables live as long as the process lives). Such elements are named Activity objects. The same is true for custom classes. If one or more of the class global variables is of a UI type (or any activity object type) then the class will be treated as an "activity object". The meaning is that instances of this class cannot be declared as process global variables." (http://www.b4x.com/forum/basic4andr...orials/18626-classes-tutorial.html#post106825)
It looks as a way around this is to let activityA add an instance of an "activity object" custom class to a process global list in a Code module. Then you can let:
If an other activity, activityB is started:
Is there a way to go so the class instance can handle events from views in more than one activity? For example, is it possible to let the class instance be created outside the context of an activity?
Erel say that "Android UI elements hold a reference to the parent activity. As the OS is allowed to kill background activities in order to free memory, UI elements cannot be declared as process global variables (these variables live as long as the process lives). Such elements are named Activity objects. The same is true for custom classes. If one or more of the class global variables is of a UI type (or any activity object type) then the class will be treated as an "activity object". The meaning is that instances of this class cannot be declared as process global variables." (http://www.b4x.com/forum/basic4andr...orials/18626-classes-tutorial.html#post106825)
It looks as a way around this is to let activityA add an instance of an "activity object" custom class to a process global list in a Code module. Then you can let:
-the custom class instance add views to activityA
-the custom class store a reference to the view in a class global variable
-the custom class handle the events from the views in a class member sub.
-the custom class store a reference to the view in a class global variable
-the custom class handle the events from the views in a class member sub.
If an other activity, activityB is started:
-The activityB can access the class instance stored in the process global list
-The class instance can add views to activityB
-But the class instance can not handle the events from the views added to activityB
-The class instance can add views to activityB
-But the class instance can not handle the events from the views added to activityB
Is there a way to go so the class instance can handle events from views in more than one activity? For example, is it possible to let the class instance be created outside the context of an activity?