Android Question From Service Call some SUB in B4XPage

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

please, how can I call some SUB which is in B4Xpage from service?

I want to do in service something like this:
B4X:
CallSub(B4XPage1, "Showlabel")

Best regards
p4ppc
 

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, Mr. Erel,

I have old app, I have services there and I combine now this old app with B4Xpage. I have for example :
- service for detecting (receiving) sms
- service where I am using httputils

and I am finding way how can I call from this services some SUB in some B4Xpage. It is for me very useful, because when
I am trying to detect (in B4Xpage) some task in service which take only few milisecond then I am trying to do that with
timer, where I am reading some variable declared in service , but it is not good solution, because everytime it is not
possible to detect some short task because of timer...

Best regards
p4ppc
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I think Erel wanted to suggest that you move the code from the services to the B4XPages (*). If I was wrong... I suggest it to you ?

However, you can call a routine (sub) of a B4XPage using CallSub (or CallSubDelayed) in a simple way, as you wrote yourself, as long as you can access the page (ie that object); for example if it is declared as Public in the B4XMainPage:

B4X:
CallSub(B4XMainPage.B4XPage1, "Showlabel")


(*) P.S. That way you can create B4I or B4J versions of your project easily.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
I actually call the sub directly like this example from Starter Service GPS handling
B4X:
If (B4XPages.IsInitialized) Then
    B4XPages.MainPage.Location_Changed(Location1)
End If
 
Upvote 1

Erel

B4X founder
Staff member
Licensed User
Longtime User
- service for detecting (receiving) sms
Is it a foreground service? If not then it will be killed after the app moves to the background.

B4XPages are not paused as long as the process is running. Unless you really need to do something in the background then you should move the code to one of the pages classes.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, thank you very much,

Mr.Erel:
I have SMS service as
B4X:
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER

and LucaMs, Alessandro71

thank you very much for your help,
Best regards
p4ppc
 
Upvote 0
Top