Android Question Creating Long time running apps in background

Discussion in 'Android Questions' started by billyn_hk, Sep 13, 2015.

  1. billyn_hk

    billyn_hk Member Licensed User

    Does anyone happen to know how to create a long run background service like whatsapp ?
     
    Last edited: Sep 14, 2015
  2. JohnK

    JohnK Active Member Licensed 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
     
  3. marcick

    marcick Well-Known Member Licensed User

    Dose not StartServiceAt work fine ?
     
  4. billyn_hk

    billyn_hk Member Licensed User

    yes, it will not start if OS were to kill the app upon system resource tight.
     
  5. marcick

    marcick Well-Known Member Licensed 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.
     
  6. billyn_hk

    billyn_hk Member Licensed 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.
     
  7. marcick

    marcick Well-Known Member Licensed User

    Strange, shouldn't happen I think, but wait comments of some experts.
     
  8. billyn_hk

    billyn_hk Member Licensed User

    thanks marcick. everyone are so nice here.

    :)
     
  9. DonManfred

    DonManfred Expert Licensed User

    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.
     
  10. JohnK

    JohnK Active Member Licensed User

    and never forget that on a phone, a battery could run out of charge or the user can reboot at any time.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice