Reputation: 11416
i am using Paho Android Service API
and I onnect in onResume
and disconnect in onPause
. At run time, I can subscribe
from the device and see the published
messages from the PC through mosquitto Broker
. when I press he BackButton
the App crahses and shows the below logcat
errors.
kindly please let me know how to solve this issue.
to Note:
1_since i am using Paho Android Service API
i imported the required libraries into the project. And
within the application
element of the manifest file of my project i have added this line
2_i am not registering any receivers in my frament, the receiver in included in the library i imported to use Paho API
<!-- Mqtt Service -->
<service android:name="org.eclipse.paho.android.service.MqttService" >
</service>
LogCat:
Activity com.example.mqtt_test_00.MessaginActivity
has leaked IntentReceiver org.eclipse.paho.android.service.MqttAndroidClient@43075698 that was
originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Activity
com.example.mqtt_test_00.MessaginActivity has leaked IntentReceiver
org.eclipse.paho.android.service.MqttAndroidClient@43075698 that was originally registered here.
Are you missing a call to unregisterReceiver()?
at android.app.LoadedApk$ReceiverDispatcher.
<init>(LoadedApk.java:814)
at
android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:610)
at
android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1762)
at
android.app.ContextImpl.registerReceiver(ContextImpl.java:1742)
at
android.app.ContextImpl.registerReceiver(ContextImpl.java:1736)
at
android.content.ContextWrapper.registerReceiver(ContextWrapper.java:478)
at org
.eclipse.paho.android.service.MqttAndroidClient.registerReceiver(MqttAndroidClient.java:410)
at
org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:388)
at
com.example.mqtt_test_00.Sub_Frag$5.onClick(Sub_Frag.java:98)
android.app.ServiceConnectionLeaked: Activity
com.example.mqtt_test_00.MessaginActivity has leaked ServiceConnection
org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection@430756f0 that was
originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>
(LoadedApk.java:988)
at
org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:385)
at
com.example.mqtt_test_00.Sub_Frag$5.onClick(Sub_Frag.java:98 )
Upvotes: 2
Views: 1635
Reputation: 21
MqttAndroidClient has method named unregisterResources which will unregister receiver if any.
The usage is something likes this
MqttConnection connection = MqttConnections.getInstance(this).getConnection(clientHandle); connection.getClient().unregisterResources();
Upvotes: 0
Reputation: 11416
I would not repeat what aother members have suggested and recommnded, but the only thing I would like to say is that, calling client.disconnect
would unregister
the service
. Have you called disconnect
?
Upvotes: 0
Reputation: 1413
Your issue is:
11-21 13:26:51.703: E/ActivityThread(28310): android.app.IntentReceiverLeaked: Activity
com.example.mqtt_test_00.MessaginActivity has leaked IntentReceiver
org.eclipse.paho.android.service.MqttAndroidClient@43075698 that was originally registered here.
Are you missing a call to unregisterReceiver()?
your not unregister service in same class ,so your got this issue,try like this,
@Override
public void onPause() {
super.onPause();
try
{
unregisterReceiver(this.intentReceiver);
}
catch(Exception e)
{
e.printStackTrace();
}
}
Upvotes: 0
Reputation: 4570
The logcat is pretty clear about the situation. It seems like you're not unregistering a receiver.
You should do that by calling unregisterReceiver() in one of the life-cycle methods(onPause(), onStop()) your Activity has.
unregisterReceiver(yourReceiver);
Where yourReceiver is most probably an instance of MqttAndroidClient(per logcat output)
Upvotes: 1