Reputation: 1520
I have written BluetoothGattCallback
in my activity. I also have a foreground service
running to capture user location.
When I kill my app, I can see advertisement packets from Bluetooth Low Energy
keeps receiving in onCharacteristicChanged
.
But when I removed foreground service
, as soon as I kill the app, advertisement packets from Bluetooth Low Energy
stops receiving in onCharacteristicChanged
(which is desired state).
How can I stop advertisement packets from Bluetooth Low Energy
in onCharacteristicChanged
when I kill app?
Upvotes: 0
Views: 89
Reputation: 18497
I think your definition of "kill app" really means "destroy the running activity", which is not the same thing as "killing the app process".
The Bluetooth API is completely separate from the Activity logic. Unless you actively do something to stop the notifications from arriving in your app process, and unless the Bluetooth connection geats teared down, they will keep coming until the app process is killed.
If you want the Bluetooth connection to stop when you destroy your Activity, you need to have some logic in the onDestroy
method in your Activity (or in the onDestroy
method of a service that your Activity is bound to) that for example makes sure the close
method is called on your BluetoothGatt
object.
Last thing, what you get in onCharacteristicChanged
is notifications or indications. Not advertising packets. Advertising packets is what you get when you perform a scan.
Upvotes: 1