I have a sensor which connects with my app via bluetooth. I have created a Foreground service which keeps the app active and connected with the sensor even after user close the app. To stop the Foreground service, user relaunch the app and stops the foreground service.
All the above is done perfectly and works fine for NOW.
My problems are -
There is a play and pause button to start and stop the service. Once started, the icons changes but relaunching the app after closing the app completely (without stopping the foreground service), app doesn't change. Of course it doesn't change because I have no idea how to check if service is still running in the foreground or not.
Yes, I have read all the previous answers and most of them are either deprecated or doesn't work anymore.
Since Commonsware is asking for the link for all the posts I have read so far, here you go -
- Determining the current foreground application from a background task or service
- How to check is app in foreground from service?
- check android application is in foreground or not?
- Check if Foreground service is running in Android OREO
- How to determine if an Android Service is running in the foreground?