Android Question service stops running after closing app

ronell

Well-Known Member
Licensed User
Longtime User
i have a service running in my app that intercepts message

main activity code
B4X:
Sub Activity_Create(FirstTime As Boolean)
    StartService(smsinterceptor)

service code
B4X:
#Region  Service Attributes
    #StartAtBoot: True
   
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim si As SmsInterceptor
End Sub

Sub Service_Creates
   
End Sub

Sub si_MessageReceived (From As String, Body As String) As Boolean
    Log("SMS RECEIVED")
   
 
End Sub
   
Sub Service_Start (StartingIntent As Intent)
    si.Initialize2("si",999)
   
End Sub

Sub Service_Destroy

End Sub

everytime i received a message the messagereceived event is raised but when the app is close(swiped/killed) , the event is not being raised .. how can i make the service running even if the app main activity is not visible
 

KMatle

Expert
Licensed User
Longtime User
how can i make the service running even if the app main activity is not visible

Working with intents mean that you service is (re)created if an intent (here sms) occurs. To be exact: It is not "running", you just set "call this service if...." So there must be something else. If you have a Huawei phone take care that your app is set to protected. Otherwise it is stopped when the phone goes to sleep.

You can try to set the phone wake state (search the forum how to do that).
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top