My application sends an sql insert query everytime the telephone is tilted at more than 45°
I need either to stop the user from quitting the application or have it still running in the background so that it still sends the queries
basically I need the application to be running all the time, any ideas? thanks
One thing is for sure - do not prevent the users from quitting the application. There is, however, a wakelock that can keep the processor on despite being out of the app, using the wakelock flag PARTIAL_WAKE_LOCK. Look into services and wakelock.
ReplyDeleteLook here for more information on PowerManager and WakeLock, and here for more information on Services. This link is also pretty helpful regarding a demo on how to use a Service, and this StackOverflow question displays how to properly setup a WakeLock (although you'd want to replace SCREEN_DIM_WAKE_LOCK with PARTIAL_WAKE_LOCK for your purpose).
You should create a Service. This will run in the background executing the SQL inserts while leaving the user free to interact with their phone and answer calls. Remember to keep in mind battery usage and CPU resources while it is running.
ReplyDeleteAnother common technique is to add a status bar notification while the service is running. This informs the user that the app is still running in the background, and allows them to bring a relevant activity back to the foreground by selecting it.