Android Question Creating Long time running apps in background

billyn_hk

Member
Licensed User
Longtime User
Does anyone happen to know how to create a long run background service like whatsapp ?
 
Last edited:

JohnK

Active Member
Licensed User
Longtime User
You have to remember that you and your app are a "guest" on the Android system, at the discretion of the "Android Overlord". Your app is no more important than the latest "Flappy Bird" clone. Unless...

You will probably need a rooted phone, with super user installed. I have used the following in scripts, but never through B4A, so there may be an Android/Java interface as well, I just haven't checked.

Look into setting your OOM value and Renicing your process id; careful, the values are in reverse order ie lower means higher... for at least one of them and also go into -ve for OOM I think. I previously had a phone with only 512mb ram and setting these values to the extreme did a pretty good job of limiting Androids ability to randomly kill processes. In my case, it would previously kill my background music player while I was using Navigation (Google Maps)

But even with the above, i don't think you will get around a "Force Stop" in Settings/Apps
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Hope not to misunderstand your question.
If each time the service is started you add a StartServiceAt, the service should restart again after specified time, also if the OS kill the app.
StartServiceAT is based on alarm timer of the device, the OS can't kill that.
 
Upvote 0

billyn_hk

Member
Licensed User
Longtime User
you are correct.
But some mobile phone manufacturer have modification on their own Rom.
StartServiceAt will not be called if the app was killed by OS on this situation.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
StartServiceAt will not be called if the app was killed by OS on this situation.
If the App is terminated manually by the user (with a taskmanager for example) it won´t restart the service unless the user manually started your app again.
 
Upvote 0

JohnK

Active Member
Licensed User
Longtime User
and never forget that on a phone, a battery could run out of charge or the user can reboot at any time.
 
Upvote 0
Top