Android: What is the best way to do repetitive Android Oreo background tasks?

I heard that background services will not work this free on android Oreo. I'm a little confused about how to rewrite my Code. I have been working with Android for a month or so, so please try the answer as simple as possible.

I have a service called On Boot and in onCreate()my MainActivity. In the service, onStartCommandit calls Handler. This handler will postDelay()itself every half minute and calls the function. This function executes some api requests and will trigger a notification under certain conditions.

What is the best way to use this code for android O +?

I thought about using the Foreground service and displayed a useless notification ongoing, the user can make it invisible, but this idea does not sound very good.

+4
source share
2 answers

This handler will call postDelay () every half minute and call the function

This will not work reliably on Android 6.0+, thanks to Doz mode and application standby time. In particular, working anywhere will almost always be bad for the battery, and therefore Google will be very busy to prevent this behavior.

What is the best way to use this code for android O +?

, . JobScheduler (, 15 ).

, Android 8.0+ , Android 6.0+ (.. - , , , ).

Foreground , , .

, .

+1

GcmNetworkManager. . api, , , oreo.

0

Source: https://habr.com/ru/post/1684486/


All Articles