Task not running on service mode

Shay

Well-Known Member
Licensed User
Longtime User
Hi

I have the following code, that suppose to listen to incoming SMS, while in background (as service)
while it is in background it is not catching incoming SMS
any idea why?

Dim SI As SmsInterceptor

Sub Service_Start

SI.Initialize("SI")

n.Initialize
n.Icon = "icon"
n.SetInfo("Barrier Plus", "Running in background", MainMenu)
n.Vibrate = False
n.Notify(1)

End Sub

Sub SI_MessageReceived (From As String, Body As String)
MessageFrom1 = From
MessageBody1 = Body
Check_Arrived_SMS
End Sub
 

thedesolatesoul

Expert
Licensed User
Longtime User
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
it is not been destroyed
also tried running as forground, still is not catching the SMS
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
I have put break point on all the subs
and while the service is in the background it is not entering any sub

the Check_arrived_SMS sub, is some functions to run on the arrived SMS
but it never reach it, since the SI_MessageReceived is not triggered
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
I cannot upload the project

The problem is only the service part here it is, also here is how I call it

Sub Image_SMS_Start_Click

If ServiceModule.ServiceRunning = False Then
StartService(ServiceModule)
ServiceModule.ServiceRunning = True
Image_SMS_Start.Visible = False
Image_SMS_Stop.Visible = True
ToastMessageShow("Running in background", True)
Activity.Finish
End If

End Sub


'------------------------
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

Dim MessageFrom1 As String
Dim MessageBody1 As String
Dim SI As SmsInterceptor
Dim ServiceRunning As Boolean
Dim n As Notification
Dim PhoneCall As PhoneCalls
Dim PhoneNumber As String

End Sub

Sub Service_Create

End Sub

Sub Service_Start

' Dim aa As Notification
' aa.Initialize
' aa="Barrier Plus"

' Service.StartForeground(1,aa)
SI.Initialize("SI")

n.Initialize
n.Icon = "icon"
n.SetInfo("Barrier Plus", "Running in background", MainMenu)
'Change Main (above) to "" if this code is in the main module.
n.Vibrate = False
n.Notify(1)

End Sub

Sub Service_Destroy
' service.StopForeground(1)
n.Cancel(1)
End Sub
Sub SI_MessageReceived (From As String, Body As String)
MessageFrom1 = From
MessageBody1 = Body
Check_Arrived_SMS
End Sub

Sub Check_Arrived_SMS
'some code....
End Sub
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
The code you have posted actually works.
I have tested it on my device.

When debugging services etc, it is probably a good idea not to use breakpoints, msgboxes and other invasive debugging techniques.
Better to use Logs and Toastmessages.
I received a toastmessage from inside the SI_MessageReceived event so I am sure that the event is firing.
I am not sure why I couldnt get Logs to work with B4A-Bridge but I will fix that later.

Now unless you post further details especially about Check_Arrived_SMS I do not know how people are supposed to help you.
 
Upvote 0

Shay

Well-Known Member
Licensed User
Longtime User
ok, you are correct
I have put toast message and I got it while getting SMS
Now I will check the rest of the code, and if it is related I will post it here

b.t.w - do you know if the service will work while device is in "sleep" mode (screen saver)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…