Android Question [SOLVED] Timer in starter service stops ticking after some time

Discussion in 'Android Questions' started by rleiman, Apr 18, 2018.

  1. rleiman

    rleiman Well-Known Member Licensed User

    Hi Everyone,

    Apart from the default coding that's created when a new app is created, do I need to add anything to keep my timer ticking in the starter service? It stops after a few hours of having the device screen off.

    Thanks.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Call Service.StartForeground and acquire a partial lock with PhoneWakeState. Otherwise the OS will kill the process when it is in the background.
     
  3. rleiman

    rleiman Well-Known Member Licensed User

    Hi Erel,

    Thanks for the reply.

    We have a lot of apps that are using Service.StartForeground but can't actually run them on our test Samsung S7 phone running Android 7.0 if we re-compile them with the current version of B4A. Each app crashes as soon as Service.StartForeground executes. All of our apps that were compiled with the previous version of B4A will not crash when run on that phone.

    Maybe the crashing is caused by the other issue we have faced with using notifications after compiling with the current B4A version. That issue crashes our test phone as well. We were able to do a work-around by initialising the notification every time it's used like in the following code in which case does not crash the app:

    In a sub routine.

    Code:
    nNotify.Initialize
                    nNotify.Icon = 
    "icon"
                    nNotify.Sound = 
    False
                    nNotify.Light = 
    False
                    nNotify.Vibrate = 
    False
                    nNotify.SetInfo(
    "Our App""Our message.""")
                    nNotify.Notify(
    2)
    In our original existing apps, we initialised nNotify first and re-used the notifications like this:

    Service_Create:

    Code:
    nNotify.Initialize
                    nNotify.Icon = 
    "icon"
                    nNotify.Sound = 
    False
                    nNotify.Light = 
    False
                    nNotify.Vibrate = 
    False
    In a sub routine:

    Code:
    nNotify.SetInfo("Our App""Our message.""")
                    nNotify.Notify(
    2)
    In a another sub routine:

    Code:
    nNotify.SetInfo("Our App""A different message.""")
                    nNotify.Notify(
    2)
    We already tried to initialise nNotify prior to using using the following without success:

    Code:
    Service.StartForeground(4, nNotify)
        wakeState.PartialLock
    The app runs only if we comment out the StareForeground statement.

    Is there an alternate statement we can use to start the service in foreground mode?

    Thanks.
     
  4. rleiman

    rleiman Well-Known Member Licensed User

    Hi Erel,

    How do I edit the title of this posting? I need to mark it as solved. I used the following coding instead of
    Service.StartForeground. At lease it will force the serveric to run in the foreground.

    Code:
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
    I do have one more question. Can we tell this statement not to vibrate the phone and not have a notification sound? Most of our customers don't want it to do that. That's why we turn those off when we initialise the notifications.

    Thanks so much.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Upper right corner:

    [​IMG]

    Please start a new thread for a new question.
     
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