Service does not restart on certain phones when app closed by task manager

53 views
Skip to first unread message

Matt

unread,
Feb 26, 2019, 6:49:05 AM2/26/19
to DroidScript
Hi all,

I have a test phone that I am using to fault find issues with my apps that I develop on a seperate tablet.

One of my apps has a service that ticks in the background but it seems to stop when you close the app using the android task manager.

I have read other posts on this forum and I understand that this is not the proper way to close an app but that the service should restart anyway.

This works just fine on the tablet that I develop on but once I transfer the apk to the phone and install it, it does not behave in the same way as the service stops once the app is closed.

The phone I am using is a cheap ulefone s10-pro with Andriod 8.1.0

I have read that this could be the case for certain phones but is there a way around it as I cannot control the phone models that will be running the apps.

Regards,
Matt
ServiceTest.spk

Steve Garman

unread,
Feb 26, 2019, 7:26:48 AM2/26/19
to DroidScript
I haven't looked at your spk but it sounds like what you need is a foreground service.

In the OnStart function of Service.js try adding a line like this

app.SetInForeground( app.GetAppName(),"Service Running" );

Matt

unread,
Feb 26, 2019, 7:54:38 AM2/26/19
to DroidScript
That did the trick, thank you greatly!

I cannot seem to find any notes/documentation on that method though so are there any risks/downsides to having a "foreground" service?

Chris

unread,
Feb 26, 2019, 8:31:53 AM2/26/19
to DroidScript
Nope. Minus the persistent notification, which is a android requirement.

It is the only way on Android 8+ to keep a service running when the main app is closed. A quick google of 'android foreground service' should explain everything you need to know. :-)

Reply all
Reply to author
Forward
0 new messages