0

I start a service from a foreground activity with the following way:

    Intent i = new Intent();
    i.setComponent(new ComponentName("com.xxx.yyy", "com.xxx.yyy.SyncService"));
    ComponentName c = ctx.startService(i);

But i get this exception

Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { ... }: app is in background uid NULL

I call the startService from my app which is in the foreground, so restrictions Limits dont apply here.

HOWEVER

If i start manually the other app which holds the service and put it on the background, and then from my app call the service, works fine. But only if the other app is running in the background.

  • The restriction is on the app that has the Service, not the app that's starting the Service. – TheWanderer Dec 10 '18 at 11:14
  • Please add complete logcat – Pallavi Tapkir Dec 10 '18 at 11:19
  • The background restriction. Unless you use `startForegroundService()` the app that has the Service has to currently be in the foreground, not the app that's calling `startService()`. – TheWanderer Dec 10 '18 at 11:34
  • I've already told you twice. – TheWanderer Dec 10 '18 at 11:35
  • @TheWanderer Okay, but why when i start the app that has the service and then i reopen my app (service app goes to background) to call that service works fine? The service app is still in background. –  Dec 10 '18 at 11:37
  • It's not. You have an Activity running. Leave the Activity in Recents for a while and it'll move to the background state. – TheWanderer Dec 10 '18 at 11:38
  • @TheWanderer Iam confused. When you press the home button an app/activity goes to background right? –  Dec 10 '18 at 11:42
  • 1
    Not immediately. There's a difference between the visual background and the process background. – TheWanderer Dec 10 '18 at 11:42
  • @TheWanderer okay thankss. Is there a link to read about visual background and the process background? –  Dec 10 '18 at 11:44
  • The same question is being answered here (https://stackoverflow.com/questions/46445265/android-8-0-java-lang-illegalstateexception-not-allowed-to-start-service-inten) – rajat singh Dec 10 '18 at 12:07

0 Answers0