A App Dude Active Member Licensed User Longtime User Dec 8, 2018 #1 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 ... Code: 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 ... Code: Sub Activity_Create(FirstTime As Boolean) 'Do not forget to load the layout file created with the visual designer. For example: Activity.LoadLayout("BLESelector") bleMgr.Scan(Null) 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? Thanks. Last edited: Dec 8, 2018
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 ... Code: 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 ... Code: Sub Activity_Create(FirstTime As Boolean) 'Do not forget to load the layout file created with the visual designer. For example: Activity.LoadLayout("BLESelector") bleMgr.Scan(Null) 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? Thanks.
BillMeyer Well-Known Member Licensed User Longtime User Dec 8, 2018 #2 In your second activity use: Code: Main.bleMgr.Scan(Null) 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
In your second activity use: Code: Main.bleMgr.Scan(Null) 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".
A App Dude Active Member Licensed User Longtime User Dec 8, 2018 #3 Excellent... that works. Thanks! Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Dec 9, 2018 #4 Don't manage BLE from an Activity. Use the starter service for this: https://www.b4x.com/android/forum/threads/ble-2-bluetooth-low-energy.59937/ Upvote 0
Don't manage BLE from an Activity. Use the starter service for this: https://www.b4x.com/android/forum/threads/ble-2-bluetooth-low-energy.59937/