I have android app using google maps API. When the app is running and user doesn't interract with it app still works and system doesn't go to sleep. However I need to close it if user doesn't interract with app some while. Is there any solutions?
Asked
Active
Viewed 98 times
1 Answers
1
There are a lot of posts regarding this topic already. A key point is that the OS handles this for you and it isn't necessary to force this behavior. If you really want to force it you could have a scheduler in your application triggered by the onStop()
method. When the scheduled task executes you can then call one of the functions mentioned in the links provided below to kill the app.
How to quit android application programmatically
A timer that will kill android app after idle for certain time?
-
Adding to this: your app should stop any significant work when you get the `onPause()` or `onStop()` callback. That is the time you should stop any active worker threads, location listeners etc. If you don't, you will drain the user's battery, which will not be appreciated. You don't need to kill your whole process to do this. – Snild Dolkow Mar 08 '16 at 19:35
-
I agree, which is also why I wouldn't really suggest calling a scheduler in onStop(). I think it's best to let the OS handle your background apps. – sam_c Mar 08 '16 at 19:38
-
point is app I need to stop app when it's not in background, I need to stop it when it's active, I mean when app is active but user doesn't interract, I need to let phone go asleep that time – Blind Despair Mar 08 '16 at 20:10
-
Is there any particular reason for forcing this? The phone will eventually sleep on its own. – sam_c Mar 08 '16 at 20:19
-
yes the reason is that user might not interract with app when it's up just to check geoposition and compare how long distance left to point. so app wakes phone from sleep, does its stuff and then it should go back to sleep, but system doesn't go to sleep when app is working, that's the problem – Blind Despair Mar 08 '16 at 20:28
-
I would use GCMTaskService to schedule periodic tasks. This should ensure the app updates at any interval you want. – sam_c Mar 08 '16 at 21:10