I use BleApp : Application()
to store BluetoohDevice, BluetoothGattCharacteristic and some state booleans. I access all of these properties from my foreground service BleService
and from activities. The BleService
should be responsible for sending a Bluetooth Low Energy (BLE) message to a BLE peripheral (LED display) each time it receives a BLE message from a smartwatch.
Is it possible that my BleService
would run independently of the app process? I mean, I don’t want that, I’m just asking if it is possible that the reference to the BleApp
used in my BleService
would somehow become null? For example, what if I use START_STICKY
in the onStartCommand
and the system kills the process due to low memory and then restarts the service when the memory becomes available again? Would be the BleApp
also available again, so I can use it’s properties and methods from the foreground service?
I have minSdk = 31 and targetSdk = 34.
I have tried adb shell am kill <package.name>
, but it does not seem to kill anything, the app process and the foreground service was still running. I am testing on a physical device, because of Bluetooth usage.
I have read this /questions/49070879/android-does-foreground-service-keep-app-alive. From the answer, it seems that as long as the BleService
is running, the BleApp
should be valid too.
But what really confuses me is that anytime I asked Bing’s Copilot, it consistently answers that a foreground service can continue executing even if he app’s process is killed by Android. So, where is the truth?
Marek Jankech is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.