Dear all,
I am using the library org.eclipse.paho.client
(https://www.hivemq.com/blog/mqtt-client-library-enyclopedia-paho-android-service)
to implement a simple Android MQTT client which connects to our MQTT server.
My Android MQTT client application worked properly until
Android OS 7.x. Unfortunately, it is not
working properly for Android 8 (Oreo version). Specifically, I received the following
exceptions:
·
android.app.ServiceConnectionLeaked: Activity.certh.gr.pedestrian.MainActivity
has leaked ServiceConnection
org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection@4058b04
that was originally bound here
·
android.app.IntentReceiverLeaked:
Service org.eclipse.paho.android.service.MqttService has leaked IntentReceiver
org.eclipse.paho.android.service.AlarmPingSender$AlarmReceiver@b9978a0 that was
originally registered here. Are you missing a call to unregisterReceiver()?
·
java.lang.IllegalStateException:
Not allowed to start service Intent { cmp=
certh.gr.pedestrian/org.eclipse.paho.android.service.MqttService }: app is in
background uid UidRecord {61f9870 …………………}
I followed the recommendations from Google for Androdi 8.0
(https://developer.android.com/about/versions/oreo/android-8.0-changes#back-all
and https://developer.android.com/about/versions/oreo/background
) , so I changed my class to extend JobIntentService and use the enqueueWork().
In the MainActivity’s
onCreate() I am calling the JobIntentService as
following:
Intent intentService = new Intent(MainActivity.this,
SimpleJobIntentService.class);
intentService.putExtra("label", intentService.toString());
SimpleJobIntentService.enqueueWork(this, intentService);
if (Build.VERSION.SDK_INT >=
Build.VERSION_CODES.O) {
startForegroundService(new Intent(this,
SimpleJobIntentService.class));
} else {
startService(new Intent(this,
SimpleJobIntentService.class));
}
where the SimpleJobIntentService
is calling the MQTT connection (MqttConnectOptions)
I am using the paho library in gradle.build:
implementation('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')
{
exclude module: 'support-v4'
}
I would like to ask you if there is any solution to this
problem or if there is any newer version which is compliant with Android OS 8
(Oreo).
Regards,
Kostas