Following crash is reported on Android 11 for Pixel devices.
Fatal Exception: java.lang.RuntimeException Unable to start activity ComponentInfo{}: java.lang.IllegalStateException: Not allowed to start service Intent {}: app is in background uid UidRecord{}
This is my code where above exception is pointing.
val stickyService = Intent(this, StickyService::class.java)
startService(stickyService)
My StickyService class extends Service class which overrides following methods.
public class StickyService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onTaskRemoved(Intent rootIntent) {
**Update value in preferences here**
}}
This is happening on Android 11 devices only. Is there major change in Service implementation in Android 11 from Google?