Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

leaked IntentReceiver when closing app #100

Open
OJ7 opened this issue Apr 8, 2020 · 1 comment
Open

leaked IntentReceiver when closing app #100

OJ7 opened this issue Apr 8, 2020 · 1 comment
Labels

Comments

@OJ7
Copy link

OJ7 commented Apr 8, 2020

In my app, I'm calling registerBroadcastReceiver (which works fine). However, I'm getting the following stack trace when closing the app (by swiping it away from the recent apps list).

com.example.app E/ActivityThread: Activity com.example.app.MainActivity has leaked IntentReceiver com.darryncampbell.cordova.plugin.intent.IntentShim$1@66e15a5 that was originally registered here. Are you missing a call to unregisterReceiver()?
    android.app.IntentReceiverLeaked: Activity com.example.app.MainActivity has leaked IntentReceiver com.darryncampbell.cordova.plugin.intent.IntentShim$1@66e15a5 that was originally registered here. Are you missing a call to unregisterReceiver()?
        at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1538)
        at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1277)
        at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1555)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1528)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1516)
        at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:636)
        at com.darryncampbell.cordova.plugin.intent.IntentShim.execute(IntentShim.java:172)
        at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
        at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
        at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
        at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
        at android.os.Looper.loop(Looper.java:181)
        at android.os.HandlerThread.run(HandlerThread.java:65)

I noticed that the plugin does not have an onDestroy method. I am able to get rid of the above log by adding the following to IntentShim.java

    @Override
    public void onDestroy() {
        Log.d(LOG_TAG, "Destroying plugin");
        this.cordova.getActivity().unregisterReceiver(myBroadcastReceiver);
        super.onDestroy();
    }
@darryncampbell
Copy link
Owner

Thanks, marked as todo - check if receiver is registered and if so, unregister during onDestroy()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants