Android Question Unstoppable service can be stopped

JackKirk

Well-Known Member
Licensed User
Longtime User
I have written an app that has a non-Starter service based on the Tracker service in Erel's MyLocation example in:

https://www.b4x.com/android/forum/threads/background-location-tracking.99873/

The service I have written contains a Service_Start subroutine:
B4X:
Private Sub Service_Start (StartingIntent As Intent)
    
    'Set up a starter notification
    Private wrk_notif As Notification
    wrk_notif.Initialize2(wrk_notif.IMPORTANCE_LOW)
    wrk_notif.Icon = "icon"
    wrk_notif.Sound = False
    wrk_notif.Vibrate = False
    wrk_notif.SetInfo("TreeTops http messages", "Started...", Main)

    'Bring service to foreground state and display starter notification - fires
    'activities in Main
    Service.StartForeground(Main.Gen_notification_id_low, wrk_notif)
    
    'Start service again in 60 secs
    StartServiceAt(Me, DateTime.Now + 60 * DateTime.TicksPerSecond, True)

    'Check for messages
    Checkmsg
    
End Sub

where Checkmsg goes off and checks for messages in an AWS S3 bucket.

In one of the posts in the above referenced thread Erel states:
This app is intended to always run so it is never stopped.

And this is generally true - if I manually try to kill it it rises again on schedule.

However I have found that I can permanently kill it with Kapersky's Battery Life app:

https://play.google.com/store/apps/details?id=com.kaspersky.batterysaver

This app allows you to kill everything in sight - but it warns that some apps will resurrect themselves.

And sure enough apps like Google Play Store will arise again.

But my app doesn't.

How can I make my app replicate the behaviour of Google Play Store?
 

JohnC

Expert
Licensed User
Longtime User
I have a hunch that Google apps use a undocumented process priority level that is not available to other apps.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I have a hunch that Google apps use a undocumented process priority level that is not available to other apps.
Thanks for your interest JohnC, but I just used Google Play Store as a "for instance" - others that do it include FaceBook.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no reliable way to keep a process running forever. A foreground service will work on many devices and will be stopped after a while on some devices.

If the user explicitly kills the app from Settings - Applications then your app will be stopped and will not restart.
Popular apps such as Facebook might be treated differently on some devices.

You can add push notifications as another method to start the app.
 
Upvote 0
Top