Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android O limits for lower target SDK

Tags:

android

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?
like image 210
NickF Avatar asked Jun 11 '17 14:06

NickF


1 Answers

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

like image 147
vokilam Avatar answered Oct 05 '22 12:10

vokilam