paho.mqtt.android
paho.mqtt.android copied to clipboard
Crash - Not Allowed to Start Service Intent
Please fill out the form below before submitting, thank you!
- [x] Bug exists Release Version 1.1.1 (Java Repository Master Branch)
- [ ] Bug exists in Snapshot Version 1.1.2-SNAPSHOT (Android Service Repository Master Branch)
- [ ] Bug is just in the Sample Application.
Bug Seen on API 27(Oreo 8.1.0), Pixel
Console Log output (if available):
Exception java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.plangram.plangram.plangram/org.eclipse.paho.android.service.MqttService }: app is in background uid UidRecord{accd403 u0a307 LAST bg:+6m35s58ms idle change:cached procs:1 seq(188,188,188)} android.app.ContextImpl.startServiceCommon (ContextImpl.java:1521) android.app.ContextImpl.startService (ContextImpl.java:1477) android.content.ContextWrapper.startService (ContextWrapper.java:650) org.eclipse.paho.android.service.MqttAndroidClient.connect (MqttAndroidClient.java) <OR> org.eclipse.paho.android.service.MqttAndroidClient.connect (MqttAndroidClient.java) <OR> org.eclipse.paho.android.service.MqttAndroidClient.connect (MqttAndroidClient.java) <OR> org.eclipse.paho.android.service.MqttAndroidClient.connect (MqttAndroidClient.java)
There are additional background restrictions on Oreo: https://developer.android.com/about/versions/oreo/android-8.0-changes.html#back-all
I think that if you target older sdk versions, it doesn't happen
True, just target a lower SDK for now and that should solve the issue. Long-running services are no longer allowed on Android Oreo (26) unless started in foreground mode.
On 16 Jan 2018 14:30, "Diego Plentz" [email protected] wrote:
I think that if you target older sdk versions, it doesn't happen
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt.android/issues/274#issuecomment-357960085, or mute the thread https://github.com/notifications/unsubscribe-auth/ADz40VPoPWghkaL1pm4tvrk2wgkjvLG4ks5tLKRygaJpZM4RGcW5 .
Any update on this?
I don't think this will ever be fixed cos it's not really an issue
@ingamedeo How its not an issue.
its an issue if you are bundling this in a library, as developer will use as is and app will crash.
It's not a problem with the library. What the library used to do before is not possible anymore as Android has limited background services starting from Oreo 8.0. There is no fix Perri much other than showing a persistent notification and run the service in the foreground.
On Sun, 12 Aug 2018, 17:46 Mohammad Akram, [email protected] wrote:
@ingamedeo https://github.com/ingamedeo How its not an issue.
its an issue if you are bundling this in a library, as developer will use as is and app will crash.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt.android/issues/274#issuecomment-412355592, or mute the thread https://github.com/notifications/unsubscribe-auth/ADz40aBEok3yh9j5KSCusCbZN_B4iQxDks5uQFwCgaJpZM4RGcW5 .
Then there should be a way for developer to achieve this(showing notification), if something is part of a library which is causing crash then its problem with library.
You can already do that. If you start the in the foreground a persistent notification will be shown and it should work as expected.
On Sun, 12 Aug 2018, 18:01 Mohammad Akram, [email protected] wrote:
Then there should be a way for developer to achieve this(showing notification), if something is part of a library which is causing crash then its problem with library.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt.android/issues/274#issuecomment-412356557, or mute the thread https://github.com/notifications/unsubscribe-auth/ADz40VmhSboQKxkZCBfkGHor-oM8_GEaks5uQF9-gaJpZM4RGcW5 .
Hi, I am using this library, so I think it is big issue when run on android 8.1. I can not edit to start service in foreground mode. I try to create a class, which extends MqttAndroidClient but I can not rewrite connect method. Please tell me how to fix it? Thanks!
this should be fixed by the library, starting november, only api 27 will be allowed on the Play Store, so Android 8 compatibility should be the norm
I was running into this same issue and I managed to work around it by switching from MqttAndroidClient to MqttAsyncClient.
The library should either remove MqttAndroidClient completely or rewrite it so that it works better with Android's new background restrictions. Like stated above, no one building a new Android app can reliably use MqttAndroidClient
This is definitely a problem with the library and should be fixed.
I have pulled a request for this bug, hope it can be accepted.
I don't know, but now my app not error. I don't update lib or change taget version.
I don't know, but now my app not error. I don't update lib or change taget version.
I think that if you target older sdk versions, it doesn't happen
Google Play requires that apps target API level 26 or higher.
Any updates? I'm still having this issue. Found this at Android Docs: https://developer.android.com/about/versions/oreo/android-8.0-changes.html#back-all, and this Stackoverflow post https://stackoverflow.com/a/47654126/5717211. But obviously, this would mean a change at the repo, found the specific line at MqttAndroidClient.java, line 414: Object service = myContext.startService(serviceStartIntent);
, that should be changed to something like:
Object service = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
myContext.startForegroundService(serviceStartIntent) :
myContext.startService(serviceStartIntent);
Bu I don't have a lot of experience in services, so I don't know exactly if this would work.
Any updates? I'm still having this issue
Fatal Exception: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.psa.mym.myds/org.eclipse.paho.android.service.MqttService }: app is in background uid UidRecord{e841909 u0a96 SVC bg:+2m11s429ms idle change:uncached procs:1 proclist:8441, seq(0,0,0)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1688) at android.app.ContextImpl.startService(ContextImpl.java:1633) at android.content.ContextWrapper.startService(ContextWrapper.java:683) at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:414)
From oreo, you are not allowed to start service from background. So its bug. You have to change library and use broadcast to start service
On Mon, 8 Jun 2020 at 1:57 PM, Assadi Mondher [email protected] wrote:
Any updates? I'm still having this issue
Fatal Exception: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.psa.mym.myds/org.eclipse.paho.android.service.MqttService }: app is in background uid UidRecord{e841909 u0a96 SVC bg:+2m11s429ms idle change:uncached procs:1 proclist:8441, seq(0,0,0)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1688) at android.app.ContextImpl.startService(ContextImpl.java:1633) at android.content.ContextWrapper.startService(ContextWrapper.java:683) at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:414)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt.android/issues/274#issuecomment-640451132, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGNF7TG5PJDASWTM5ZT76LTRVSOIHANCNFSM4EIZYW4Q .
-- Thanks and Regards : Amit Jaiswal http://linkedin.com/in/amit-jaiswal-b62a1a7b (Android Engineer)
What is exactly issue, could you explain your business logic then I might help you
On Fri, 16 Oct 2020 at 10:37 PM, Eduardo de Oliveira Freitas < [email protected]> wrote:
Is there any solution to this problem?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/paho.mqtt.android/issues/274#issuecomment-710237251, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGNF7TFNDYKWKC55HEPVWY3SLB4WJANCNFSM4EIZYW4Q .
-- Thanks and Regards : Amit Kumar Jaiswal http://linkedin.com/in/amit-jaiswal-b62a1a7b (SDE- I Android)
Hi everybody,
even if its the year 2023 I would like to give my 50 cents to the topic. First some background info why I made some investigations in this area:
- I have a production app which utilises MQTT for a messaging module. E.g. to send a notification to the user once a message arrives while the app is killed or in background or device screen is locked
- I am using a dedicated ForegroundService (another one besides Mqtt Background Service from Paho aka MqttService.java)
- I have faced some
BackgroundStartServiceNotAllowedExceptions
via Crashlytics and that's the reason why I started to look into the issue
As far as I understood it is still allowed to start a background service on android, e.g. see https://developer.android.com/guide/components/services. Starting from apiLevel 26 on there are some restrictions to start a background service. One restriction is that you can not start your background service while your app is not in the foreground. Regarding background service we can sum up that:
- A background service is terminated once the app is terminated/killed by the user
- Prior Android O (Android 8.0, ApiLevel 26) a background service is running forever if app is moved to background
- On Android O (Android 8.0, ApiLevel 26) or higher a background service is stopped after a while if app is moved to background
So what I actually think is that there is nothing wrong about the paho mqtt android client (MqttAndroidClient) which starts the MqttService as a background service via Object service = myContext.startService(serviceStartIntent);
on Line 415 of MqttService.java. All you have to make sure is that your app is in foreground once you start paho's MqttService and you should also start your own foreground service which displays a notification to the user telling him that there is some process/service of your app running even if you killed your app. What this foreground service actually does is that it keeps your android app process alive so that the MqttService is also alive and keeps working. In my special case I start the paho MqttService & my own foreground service once the user is logged in and stop it once the user logs out.
There are some forks of this library to work around this issue, like this one, but I think you won't need this.
One issue I have found is that the service did not call onDestroy by only using disconnect
. I had to remove any registered resources/callbacks and needed to close the connection, see https://github.com/eclipse/paho.mqtt.android/issues/234
I hope this is not total nonsense and my assumptions do fit at least a bit ...