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

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.
 

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.

B4X:
                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:

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

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

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

B4X:
    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.
 

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.

B4X:
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.
 
Top