I am currently making an app that will control and make use of the light sensor. As such I need data for when the ambient lighting changes (via the light sensor in lux). How would I make it so that when the user exits my application that it stays running in the background with the ability to collect data and make changes to the system?
Share
If you do not un-register your sensors from your sensor manager on OnPause() your sensor event listener events should still be getting being fired at regular intervals. You should then be-able to do what ever functionality you need from there. However if the user stops the program and the system sees that its been inactive for a while and its system memory is running low there is a possibility that the android OS will kill the task thinking its not needed. I am sure there are some flags or something to be called to stop this from occurring but I cant tell you off the top of my head.
You could also look into writing a background service if you want it to run all once the user boots-up.