Android Question Can't share variable between activities

App Dude

Active Member
Licensed User
Longtime User
I have 2 activities in my app, and can't seem to share an object between them. I've added both activities as modules.

(1) In my main activity, I have ...
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public bleMgr As BleManager2
End Sub

In the second activity, I have ...
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

But I get a compilation error...
"Error description: Undeclared variable 'blemgr' is used before it was assigned any value."

I tried moving the bleMgr declaration to the Service_Create sub in the Starter activity, but then it doesn't work in either activity.
(BTW, I'm initializing etc but not showing that as I don't see it being relevant here)

I am able to share an Int variable without any errors. Is there something specific about the BleManager2 that makes it have this issue? Or what else am I missing here?

Last edited:


Well-Known Member
Licensed User
Longtime User
In your second activity use:

If you declare "public" in an activity and you wish to refer to it, you always need to prefix its name - in this case "Main".
Upvote 0