Android Question Stoping Service completely

khwarizmi

Active Member
Licensed User
Longtime User
Hi all
I have an application that has a service tied to a specific task so that it starts on startup.
B4X:
#StartAtBoot: true
How can I stop the service completely? Note that:
B4X:
StopService("tahServ")
stops the service temporarily, but it returns to work when the device is rebooted?

Thanks in advance
 
Solution
Once you have the "#StartAtBoot: true", the service will always start upon boot - there is nothing you can do to stop this action when you set this option to "true".

However, if the service is not suppose to run upon boot, then you can simply add a check like this to immediately stop the service if it is not suppose to run on bootup:
B4X:
Sub Service_Start (StartingIntent As Intent)

    Dim RunOnBoot as boolean

    'set value of runonboot to a stored preference value
    RunOnBoot = [retrieve value from app preferences]

    If RunOnBoot = False then
        StopService("")   'stops current service
    Else
        'place your service code here
    End if

End Sub

JohnC

Expert
Licensed User
Longtime User
Once you have the "#StartAtBoot: true", the service will always start upon boot - there is nothing you can do to stop this action when you set this option to "true".

However, if the service is not suppose to run upon boot, then you can simply add a check like this to immediately stop the service if it is not suppose to run on bootup:
B4X:
Sub Service_Start (StartingIntent As Intent)

    Dim RunOnBoot as boolean

    'set value of runonboot to a stored preference value
    RunOnBoot = [retrieve value from app preferences]

    If RunOnBoot = False then
        StopService("")   'stops current service
    Else
        'place your service code here
    End if

End Sub
 
Last edited:
Upvote 0
Solution
Top