From onCreate()
of my Activity,
I am trying to start a service via following code:
Intent intent = new Intent();
intent.setClassName(SERVICE_PKG_NAME, SERVICE_NAME);
context.startService(intent); //context = MainActivity.this
However, I receive following exception:
java.lang.IllegalStateException: Not allowed to start service Intent (service-name) : app is in background
Any idea what could be reason for this? Stuck on it for few hours now.
For cases involving need to invoke service of Background app from a foreground app, We can follow the sequence:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With