I'm writing an app with alarm fun开发者_如何学Cctionality, i.e. it will have to continue running while the device goes into standby. Apparently, this is not the case. How can I achieve that?
It would be even better if I could prevent the device from going into standby at all - can I do that?
Android applications can prevent the device from going into standby with a wake lock but this should be used only for short periods of time for specific tasks which require the user to look at the screen without touching it.
For any other long time purposes, you have to use the system AlarmManager to schedule future actions of your application.
Using a permanent wake lock would make your app a battery drainer.
A service runs always, even in standby, so you should use it.
Preventing standby can be done with a wake lock. Be careful, there are only a few apps that should prevent standby (like games, video players...).
精彩评论