I am currently using a foreground service to check every 30 seconds if a specific bluetooth device is in range.
When it comes in range I connect to it and read data to display to the user.
I've been reading up on background services, and even though during the actual connection it should be a foreground service, while waiting to connect it should be a background one.
so I made a different service (yes I know I could just move it into foreground when it becomes connected, but I prefer to use a different service for it) which is in the background and will continuously scan for the specific mac address, when it finds it it will start the working service which will run in the background.
I don't mind the system killing my service if it is low on memory (it is not that important, plus if the user wishes to connect they can force the connection through the ui which will start the foreground service), but I would like to make sure that when there is enough memory the service is started again, is START_STICKY
enough?
In case the system destroys my service, where do I put the clean up code? will onDestroy
always fire?
Finally how can I test low memory conditions for android so as to make sure the restart goes correctly?
this has been answered here please ignore it