0

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.

Sujith S Manjavana
  • 1,417
  • 6
  • 33
  • 60
  • Does this answer your question? [Android 8.0: java.lang.IllegalStateException: Not allowed to start service Intent](https://stackoverflow.com/questions/46445265/android-8-0-java-lang-illegalstateexception-not-allowed-to-start-service-inten) – juzraai Aug 08 '22 at 08:47
  • If you *temporarily* remove `android:launchMode="singleInstance"`, does your `startService()` call work? IOW, what is your evidence that your problem is tied to `android:launchMode="singleInstance"`? You have several unusual items in that manifest entry, and your problem might not be tied to any of them. – CommonsWare Aug 08 '22 at 11:24
  • I tried to reproduce this issue but on my devices, it is working normally. I couldn't find any other reason for android to flag it as a background app while the activity is still running. – Sujith S Manjavana Aug 08 '22 at 14:54

0 Answers0