NickF
NickF

Reputation: 5737

Android O limits for lower target SDK

I started to test my app on Nexus 5x with Android O.
My targetSdkVersion is 22.
In the developer site I read about Background execution limits:
Where:
By default, these restrictions only apply to apps that target O. However, users can enable these restrictions for any app from the Settings screen, even if the app has not targetted O.

  1. Where is these settings (to enforce Android O limitations)?
  2. Whats is the best practice for these limitation while I still want to keep lower targetSdkVersion?

Upvotes: 6

Views: 574

Answers (3)

vokilam
vokilam

Reputation: 10323

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

App Info > Battery usage

[UPDATE Sep 27, 2017]

As described here:

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 your.application.id.here RUN_IN_BACKGROUND ignore 

Best practices are

  • If you plan on sticking with a lower targetSdkVersion for a while, and you are really really sure that your app will not show up on the battery blame list, and you want to ignore the background limitations for now, that’s your decision to make.

  • If, however, you plan on sticking with a lower targetSdkVersion and your app does tend to consume a fair bit of battery life, you should test your app with the adb shell appops command cited above. If nothing else, you can identify the likely symptoms that users will experience if they limit your background work through the Battery screen in Settings. That way, if you get customer service calls/emails/texts/Play Store comments/candygrams about those symptoms, you can better advise users about what to do.

See also Android Oreo Background Execution Limits

Upvotes: 1

Jan Slominski
Jan Slominski

Reputation: 2978

  1. App info > Battery usage
  2. IMO best practice is unfortunately to target API 26... This default behaviour is there only for legacy apps (sitting in play store but not being updated anymore).

Upvotes: 0

Frank
Frank

Reputation: 12298

  1. I cannot find it either.
  2. Best practise would be to develop this for API 26, although you are not targeting it. So starting your service(s) as foreground service. After that, your service should start a foreground Notification in the onCreate.

From the docs:

The new Context.startForegroundService() method starts a foreground service. The system allows apps to call Context.startForegroundService() even while the app is in the background. However, the app must call that service's startForeground() method within five seconds after the service is created. (startForeground pushes the notification)

Upvotes: 0

Related Questions