Android Question Starting Scheduled service's

Discussion in 'Android Questions' started by Jmu5667, Apr 1, 2015.

  1. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Morning All

    When the phone is fast asleep, and a scheduled service is started, how long is the service allowed to run before it is killed by the OS.

    Is it good practice to use 'service.startforeground' in a scheduled 'service_create' to keep it alive ?

    Reason I am asking I have a few services that are scheduled and one of the is for GPS positioning, and another is for Bluetooth serial comms, the two are not linked in any way.

    Regards

    John.
     
  2. Peter Simpson

    Peter Simpson Expert Licensed User

    service.startforeground will keep it alive but with a Icon at the top of the screen, even though that's simple enough to hide. Have you tried running the service as Sticky Service and using StartServiceAt(Null, xxx, True) in the service itself?

    This solution works perfectly fine for me...
     
  3. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Hi Peter

    The icon display is fine. Service is Stickyand yes I do use StartServiceAt("", xxx, True) not StartServiceAt(Null, xxx, True). So it is best practice to use service.startforeground ?

    Regards

    John.
     
  4. Peter Simpson

    Peter Simpson Expert Licensed User

    If the icon does not bother you then yes use the service.startforeground.
     
    Jmu5667 likes this.
  5. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Mmmm... after some time working on this today, I have noticed that sometime my service will pause for maybe 1-2 mins before resuming, is hooking a service to the notification object dependent on the time that is allocated to the notification object by the OS. I have reverted back to using a partial lock to do some further tests. I suspect the former is true..(as far as I can see anyways)...maybe Lord @Erel can verify this.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You should use both a foreground service and a partial lock if you want to prevent the CPU from sleeping.
     
    Jmu5667 likes this.
  7. Jmu5667

    Jmu5667 Well-Known Member Licensed User

    Thought as much.
     
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