简体   繁体   中英

Background services Android oreo (limitation)

How to handle background services with Android Oreo?

i had created intentservices and services background but due to android Oreo limitation the services stopped when the app closed

WhatsApp app works in background on android 8.1 how is this possible ?

Check this image:

Also, the broadcast receiver is not working when the app is closed

App in Foreground - Best option is to use service or Intent Service if you need to some task when application is open or in the stack.

App in Background - If you want to perform some long running periodic operation then best option is to use Jobservice running in background and Jobscheduler implementation to schedule that jobservice. Android O and above JobScheduler is recommended for background operations.

Android background services are described in the Android documentation . Google is trying to limit the freedom apps have to run services in the background for security reasons and to save battery.

You basically have the following options:

1. Foreground Service A foreground service performs some operation that is noticeable to the user. For example, an audio app would use a foreground service to play an audio track.

2. Background Service background service performs an operation that isn't directly noticed by the user. For example, if an app used a service to compact its storage, that would usually be a background service. If your app targets API level 26 or higher, the system imposes restrictions on running background services when the app itself isn't in the foreground. In most cases like this, your app should use a scheduled job instead.

3. Bound Service A service is bound when an application component binds to it by calling bindService(). A bound service offers a client-server interface that allows components to interact with the service, send requests, receive results, and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM