Android Question Service stops (Android 10)

kohle

Active Member
Licensed User
Longtime User
I added a simple app which starts a service with a timer event. The timer_tick event create a notification with a counter every 10 sec.
When the fone is unused and the screen turns black. The service is stopped or paused after about a minute, no destroy event is triggered.

I want that the service keeps alive in the background.
I used the commands from tracking gps in background example, but no success.

Some ideas what i coded wrong. Thanks for help. My code is attached.
 

Attachments

  • service_test.zip
    352.4 KB · Views: 116

Peter Simpson

Expert
Licensed User
Longtime User
@kohle using a timer for long running tasks in the service is not really recommended, there are other more stable solutions that you could implement. For starters you should look at the link below. This is just an example of how you could keep a service running in the background, but it may not work on some devices like on some Huawei devices. It does however work on all the devices I've tested it on.

 
Upvote 0

kohle

Active Member
Licensed User
Longtime User
@kohle using a timer for long running tasks in the service is not really recommended, there are other more stable solutions that you could implement. For starters you should look at the link below. This is just an example of how you could keep a service running in the background, but it may not work on some devices like on some Huawei devices. It does however work on all the devices I've tested it on.


The timer was only for a test to reproduce the problem. Indeed my phone for testing is a Huawei P30pro :( .
I reproduced the problem with some shaking lamp apps of the playstore.
Most of the apps are showing at installation a warning message of this behavior.

I am wondering why google assistent is working in standby mode. I remember that I had to give a permisson before.

My question is , is there a possibilty ?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
The timer was only for a test to reproduce the problem. Indeed my phone for testing is a Huawei P30pro :( .
I reproduced the problem with some shaking lamp apps of the playstore.
Most of the apps are showing at installation a warning message of this behavior.

I am wondering why google assistent is working in standby mode. I remember that I had to give a permisson before.

My question is , is there a possibilty ?

You could always try looking at Partial Lock, but I'm not sure if that will help or not. You could always keep an icon at the top of the screen as I believe (but I could be incorrect) that whilst your app is showing an Icon it has a better change of not getting killed by the system. You really need to look more into it.

Actually I've just remembered that my my Pixel 3XL does not really shut down services that much, but my Huawei Y6 2019 shuts down services all the time without warning.
 
Upvote 0
Top