ngd012014 / android-bluetooth

Automatically exported from code.google.com/p/android-bluetooth
0 stars 0 forks source link

easybluetooth: in LocalDevice2Impl.java, the receiver might be already unregistered when ACTION_DISCOVERY_FINISHED happens #22

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

localDevice.stopScan(); 
localDevice.destroy();

execute commands immediately after each other.

What version of the product are you using? On what operating system?
Happens on Android 2.x and 1.x

Please provide any additional information below.
It might happen that localDevice.destroy() unregisters the receiver for 
ACTION_DISCOVERY_FINISHED, but the receiver has already been called and was 
interrupted during its receive() method. When the receiver now tries to 
unregister the receiver it throws an exception.

04-02 15:16:16.523: ERROR/AndroidRuntime(30591): Caused by: 
java.lang.IllegalArgumentException: Receiver not registered: 
it.gerdavax.easybluetooth.LocalDevice2Impl$1@4474e758
04-02 15:16:16.523: ERROR/AndroidRuntime(30591):     at 
it.gerdavax.easybluetooth.LocalDevice2Impl$1.onReceive(LocalDevice2Impl.jav
a:32)

Solution:
Just surround the unregisterReceiver with a try-catch block

in Line 32 of LocalDevice2Impl.java

try {
  ctx.unregisterReceiver(receiver);
} catch (IllegalArgumentException iae) {
 //receiver was not really registered
}

Original issue reported on code.google.com by bonifaz....@gmail.com on 2 Apr 2010 at 1:26