I'm getting the following error while calling startService
from an activity.
Caused by java.lang.IllegalStateException
Not allowed to start service Intent { act=com.myapp.action.STOP_SERVICE cmp=com.myapp/.services.CallService (has extras) }: app is in background uid UidRecord{78014ac u0a419 CEM bg:+3h34m41s706ms idle procs:1 seq(0,0,0)}
My app is not in the background, but the activity is running in singleInstance
mode
<activity
android:name=".activities.CallScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_call_screen"
android:launchMode="singleInstance"
android:screenOrientation="portrait"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:taskAffinity="com.something.call"
android:turnScreenOn="true"
tools:ignore="LockedOrientationActivity"
tools:targetApi="o_mr1" />
Service
<service
android:name=".services.CallService"
android:enabled="true" />
This crash happened only a couple of times for few users(android 11). I was not able to reproduce it with my test devices. How can I avoid this crash without changing the activity launch mode? Thanks.