Our app is targeting Android O.
After reading Background Service Limitation, I have come to notice that it is safe for a foreground app to launch services. Therefore in our app we called startService() in our Fragment's onStart() method. We think this is ok because in this document it says when onStart is called, fragment is visible to the user and when it is visible, it means this app is a foreground app.
But sometimes, and I must admit it happens pretty rare, we still receive the following exception
java.lang.IllegalStateException: Not allowed to start service Intent { act=ACTION_DEACTIVATE cmp=com.adyxe.sync/.ClientService }: app is in background uid UidRecord{db2a697 u0a19 LAST bg:+7m30s540ms idle change:cached procs:1 seq(0,0,0)}
Why is this happening? Is it safer to call startService() in onResume() just to be more sure that the app is now a foreground app?