9

As per the Docs-

Note: By default, these restrictions only apply to apps that target Android 8.0 (API level 26) or higher. However, users can enable most of these restrictions for any app from the Settings screen, even if the app targets an API level lower than 26.

I'm targeting Below API 26 but i cannot find the settings to enable the restriction in official android emulator.

Where is this setting available?

Arnav M.
  • 2,500
  • 1
  • 24
  • 40

2 Answers2

6

The setting to enable the background restriction is available in App Info -> Battery screen.

Not reproducible in emulator yet.

The option is not available when you initially install the application (targeting below API 26) until the app does some background work.

So i was able to produce it by-

  1. Targeting Application at API 25
  2. Create A long running service (around 5 minutes)
  3. Starting the service from onCreate of MainActivity
  4. Send App to background(press back) and leave device on Battery(No power connected)

Within a few minutes, the option will be available to enable the restrictions.

Arnav M.
  • 2,500
  • 1
  • 24
  • 40
3

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: https://developer.android.com/topic/performance/background-optimization#further-optimization

And you can also set your app to run in background:

adb shell am make-uid-idle <package>

Source: Android Oreo Background Execution Limits

Community
  • 1
  • 1
xmarcusv
  • 63
  • 5