Android Question call subs from service

davelew1s

Active Member
Licensed User
Longtime User
Hi!
I have a main activity a class and the wifi direct service, I am trying to call a sub in the class from the service. I've tried 'callsub' and 'callsubdelayed' but I just get an error.
Is there a way to do this?
Thanks Dave.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Have you created an instance of your class? Is it within the scope of the service? If so, then just call the sub directly.
 
Upvote 0

davelew1s

Active Member
Licensed User
Longtime User
Hi Roycefer thanks for the reply. I have this in Globals 'Dim dave As daveSubs' (daveSubs being the class)this i think means it cannot be seen from other modules, if i put it in Process_Globals i get 'Cannot access activity object from sub Process_Globals'
But i have another class which is 'Dim kvs As KeyValueStore' in Process_Globals and works ok.
Not sure where to go now any idea's?
Dave.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Try something like this:
B4X:
'in Main module
Sub SomeSub
    dave.whateverSub
End Sub

And then to call it from a service:
B4X:
'in service module
CallSubDelayed(Main, "SomeSub")

This will run Main's SomeSub if the Main Activity is currently active. If not, it will start the Main Activity (provided the app is not in the background). If the app is in the background, it will schedule SomeSub to run the next time the app comes to the foreground.
 
Upvote 0

davelew1s

Active Member
Licensed User
Longtime User
OK that's what i have done as a workround. But I have found that if i comment out the kvs.keystore my class is ok it looks like something in my code but no idea what yet.I am going to get some sun for a couple of hours and have a think think.
Thanks Dave.
 
Upvote 0
Top