Use PhoneWakeState of Phone library. I don't remember the name of the method since I have closed the computer but it is the other than the method that keeps your screen from shutting off.
Simple example of a foreground service that keeps the process running in the background. The current location is shown in the persistent notification. The app starts at boot and theoretically should run all the time. It also schedules itself to run with StartServiceAt. This can help in cases...
For apps that don't need to wake up the device (like a stopwatch app), one idea is to store the start time of the stopwatch in a file, then the device could even power completely off, and when your app runs again, it will simply calculate and display the time that pasted since the stored start time.