Android Question I Stop the service - new sms is received - but the app is start again...why?

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, please for advice

in manifest editor i have

AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(receiveservice,
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)

Service is OK, everything is OK. But in APP if I click on STOP BUTTON, where I have
B4X:
StopService(receiveservice)
then APP is going to "Icone mode"

and after this if new SMS is received, then the APP is starting alone and again....(but I stoped the service with StopService(receiveservice), why it is happen?

why STOPSERVICE is not functioned in my example? What is the best solution for this task, please?
Thank you very much
p4ppc
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,
You have set a broadcast receiver in the Manifest. This means that your service will restart each time a new SMS is received.

The solution could be to save the wanted state for your service and load it each time the service is started. If it should be in stop mode so, the service would kill itself by calling StopService("") and if it should be active, it will continue to execute and after that stop itself.

So, in the Activity, your Button should manage the saving of the desired behavior.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi,

search the forum for static vs. dynamic receivers.
In short, setting a receiver in the Manifest makes it static and so the Operating System calls it everytime the event which it's listening on is raised.

udg
 
Last edited:
Upvote 0
Top