Closed cosminstefanxp closed 10 years ago
I will try to reproduce.
I too am experiencing the same thing, where it still lives even after onDestroy is called on IBeaconService. What i've noticed is that it's trying to call stopLeScan twice in that method, first via scanLeDevice(false), and then by directly invoking it through the BluetoothAdapter member variable. Also, when using a Handler, you always remove callbacks and messages from it when destroying your activity/service, or else it'll prevent the class from fully finishing/stopping. Right now, it's not clearing it in onDestroy(), so perhaps that might be it.
Edit: I was able to successfully stop the service after unbinding by calling " handler.removeCallbacksAndMessages(null)" before stopping the LE device:
@Override
public void onDestroy() {
Log.i(TAG, "onDestory called. stopping scanning");
handler.removeCallbacksAndMessages(null);
scanLeDevice(false);
if (bluetoothAdapter != null) {
bluetoothAdapter.stopLeScan(leScanCallback);
lastScanEndTime = new Date().getTime();
}
}
I have not been able to reproduce these issues using the reference application on github. Each time I hit the back button, it stops the service successfully. That said, the code proposal above sounds reasonable, so I have applied the change in ccaf2f8f9a7723275ab1808da3052480ab14d92f and put this into version 0.7.5
I am closing this issue since there have not been any additional reports or feedback since the 0.7.5 release which implemented changes to address this. Please re-open a related issue if specific problems remain.
There seem to be some issues with properly unbinding: even after calling the IBeaconManager.unbind() method, the background service still does scans and does not always stop (probably race condition).
Situation:
Due to the fact that when stopping the app, it first starts the background mode, probably goes to sleep for 1s and does not do any checks for state or existing Consumers.