Android Question "Scope"

LucaMs

Expert
Licensed User
Longtime User
[I could try it by myself, but since at this moment there is a very expert person online and I'm too lazy... ]

I have (maybe) a global instance of a my class in the Starter service.
I need to use it in more than one other "modules", an Activity, for example.

What if I declare a Private variable in the Process_Globals of the Activity and I set it with a reference to the Starter object?


[I hope it is clear ]


B4X:
' Starter
Public GlobalObj As MyClass

Sub Service_Create
    GlobalObj.Initialize

B4X:
' Activity
Sub Process_Globals
    Private mObj As MyClass

Sub Activity_Create
    mObj = Starter.GlobalObj

I think this should work. (to avoid to write Starter.GlobalObj.SomeMethod each time )
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…