Android Oreo background execution limits

Android Developers · 84K views · 2017 · 6:11

Open on YouTube

Software practice, open source & careersSoftware (other)explainerdated

Why Stack Overflow recommends it

Stack Overflow users link it as the official explanation for why background services and implicit broadcasts stopped working on Android O, and as the basis for moving to JobScheduler or foreground services.

Recommended by 3 people across 3 different months, 2017 to 2020.

What it is

A short Android Developers video explaining the background execution limits introduced in Android 8.0 Oreo, including restrictions on starting services from the background and on implicit broadcast receivers. It covers how these changes affect apps and points to JobScheduler, JobIntentService and Firebase JobDispatcher as alternatives.

What people said

Recommends Bob · 2017-08 · Stack Overflow · on “CONNECTIVITY_CHANGE Broadcast Android O”

Use JobScheduler ( JobIntentService or Firebase Job Dispatcher for backward compatibility). Refer the latest video from Android Developers [this video] . Using the method JobInfo.Builder.setRequiredNetworkType() you can schedule jobs to run when specific network conditions are met. Quoting from this thread [LINK] : The network type can be one of three values: JobInfo.NETWORK_TYPE_NONE: No network connectivity required. JobInfo.NETWORK_TYPE_UNMETERED: An unmetered WiFi or Ethernet connection. JobInfo.NETWORK_TYPE_ANY: Any network connection (WiFi or cellular). JobInfo.NETWORK_TYPE_UNMETERED would suit your needs.

Recommends SpiritCrusher · 2017-10 · Stack Overflow · on “How to always run a background service even application gets killed by user from background”

For instance below code will work on Lollipop. @Override public void onTaskRemoved(Intent rootIntent) { Intent restartService = new Intent(getApplicationContext(), this.getClass()); restartService.setPackage(getPackageName()); PendingIntent restartServicePI = PendingIntent.getService( getApplicationContext(), 1, restartService, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePI); } But Things are getting quite tricky Since android N release. And now android O put some more restrictions on background tasks

Recommends petrolhead_13 · 2020-03 · Stack Overflow · on “Xamarin Forms - Get device location every 10 seconds (when app runs in foreground/background)”

For Android you can try to start a Service that uses the LocationManager of Android to start listening to Location changes. You can specify a timeinterval and a minimum distance you want to track. This section [LINK] helped me fiqure out how to use it. For me it was sending location updates even when the app was suspended (physical device running Android 6.1). To get the location I made my Service a 'LocationListener' and implemented the ILocationListener-Interface like so: [Service] public class TestService : Service, ILocationListener { public override IBinder OnBind(Intent intent) { return null; } public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, in

Cites Patrick · 2017-08 · Stack Overflow · on “How will location apps work in Android O?”

Right now many apps track your location. However, in Android Oreo, "apps will not be able to freely run in the background" as stated in this Android Developers video [this video] . According to the developer docs [LINK] , Apps can receive location updates only a few times each hour. And for any exceptions to that rule: Consider whether your app's use cases for running in the background cannot succeed at all if your app receives infrequent location updates. If this is the case, you can retrieve location updates more frequently by performing one of the following actions: ... Start a foreground service in your app by calling startForegroundService(). When such a foreground service is active, it appe

Cites vokilam · 2017-09 · Stack Overflow · on “Android O limits for lower target SDK”

I found the setting under App info > Battery usage although not all apps have this setting. When this setting is OFF I see following logs: W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.$ACTION dat=package:$APP_PACKAGE flg=0x4000010 (has extras) } to $APP_PACKAGE/$APP_RECEIVER [LINK] [UPDATE Sep 27, 2017] As described here [LINK] : However, developers cannot use the Settings app to apply this limitation, unless their app happens to be in the battery blame list, which ideally doesn’t happen. This article offers undocumented way to test background limitations via following command ( ignore and allow values are possible) adb shell appops set you

Cites Akshay · 2017-10 · Stack Overflow · on “Service on Android Oreo”

On Android Oreo, If my app starts a service while in foreground and then I close my app, will the service be killed later on? or will it stay alive? From this video post it seems like the service will be killed if the app is in background, [this video] However, while testing, the service is quite alive. Will appreciate any productive feedback.

Cites Himadri Nath · 2018-05 · Stack Overflow · on “no Push Notification when App is inactive PubNub”

I am using xamarin and I configured FCM in my app and also PubNub. in onStart i RemovePushNotificationsFromChannels with old token and adding AddPushNotificationsOnChannels with new token inside OnTokenRefresh(). when my app is active push notification working fine. but the problem is when the app becomes inactive no more notification coming to my device but when I tested firebase console and send a test push its coming and I also monitoring this from PubNub console by subscribing with {channel-name}-pndebug. I found few moments after when app became inactive in my debug console printing this "GCM Error: NotRegistered Devices: {token}" . I searched and found this article [LINK] but with Andr

Cites ThePartyTurtle · 2018-07 · Stack Overflow · on “Samsung Galaxy S8 Android 7.0 and up Stopping Network Traffic”

I'm working on an app targeting a Samsung Galaxy S8 running Oreo or Nougat that requires constant network access in the background. The app needs to send UDP packets and access user GPS location at regular intervals at ALL times, regardless of app-standby or doze mode. I know this is not standard, but this app will not be on the Google Play store, and this network activity is mission critical to our app's functionality. I am referencing this document for development purposes: [LINK] and have made my app Oreo compliant by using startForegroundService and startForeground as described in the video below: [this video] I have added the below code to opt out of battery optimization as well: Intent inte

Cites xmarcusv · 2018-10 · Stack Overflow · on “Android O Settings to enable background restriction for applications”

You can use adb to enable/disable the background limitations. Android 7.0 (API level 24) introduces some additional Android Debug Bridge (ADB) commands that you can use to test app behavior with those background processes disabled: To simulate conditions where implicit broadcasts and background services are unavailable, enter the following command: $ adb shell cmd appops set <package_name> RUN_IN_BACKGROUND ignore To re-enable implicit broadcasts and background services, enter the following command: $ adb shell cmd appops set <package_name> RUN_IN_BACKGROUND allow Source: [LINK] And you can also set your app to run in background: adb shell am make-uid-idle <package> Source: Android Oreo Back

Cites Nishant Garg · 2018-10 · Stack Overflow · on “MediaPlayer audio playing stops when app enters in background (OREO)”

Use foreground Serive. For details on why the service will no longer work watch [this video] It clearly says that background services will be stopped. For tutorial on Foreground Services watch: [LINK] Remember you would also need to learn the notification channels starting Oreo. This guy has introduced that too.