Oreo: startService() doesn't throw IllegalStateException when called in background

前端 未结 1 694
后悔当初
后悔当初 2021-01-13 23:54

According to the background execution limits introduced in Android Oreo, calling startService when the app is in background should throw an IllegalArgumentException

相关标签:
1条回答
  • 2021-01-14 00:22

    According to Google's documentation on background service limitations:

    While an app is in the foreground, it can create and run both foreground and background services freely. When an app goes into the background, it has a window of several minutes in which it is still allowed to create and use services.

    Generally I've found the window to be something around a minute, but that can certainly be different for others.

    Take a look at your overall device logs (run adb logcat from the command line or turn off filters in Android Studio's Logcat window) after you've backgrounded the app and look for something like:

    09-26 13:25:37.150 4741 4756 W ActivityManager: Stopping service due to app idle: u0a267 -1m12s700ms com.example/.MyService

    Any request to start a service after that should cause the exception. I'm guessing you'll need to up the timeout to something closer to a minute or two.

    0 讨论(0)
提交回复
热议问题