felHR85 / UsbSerial

Usb serial controller for Android
MIT License
1.8k stars 587 forks source link

No call to unregisterReceiver() in 3 of 4 examples #188

Closed mws-rmain closed 5 years ago

mws-rmain commented 5 years ago

A call to unregisterReceiver() is missing in UsbService.java onDestroy() of the following 3 examples:

The 'examplemultipleports' does unregister for each of the detected ports.

I implemented this as shown below:

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterReceiver(usbReceiver);
        UsbService.SERVICE_CONNECTED = false;
    }

Failure to unregister throws an exception: android.app.IntentReceiverLeaked: Service <snip>.UsbService has leaked IntentReceiver <snip>.UsbService$4@7f31a07 that was originally registered here. Are you missing a call to unregisterReceiver()?

felHR85 commented 5 years ago

@mws-rmain Could you do a pull request?