One of the think you as an Android developer should properly not do is prevent the Android system from shutting down certain components to save energy.
But sometimes you need to prevent the system from sleeping, e.g. during an important update or a critical download. If you choose to do so here is how you can aquire a WakeLock:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( pm.SCREEN_DIM_WAKE_LOCK, "My wakelook"); // This will make the screen and power stay on // This will release the wakelook after 1000 ms wakeLock.acquire(1000); // Alternative you can request and / or release the wakelook via: // wakeLock.acquire(); wakeLock.release();
Again, you most likely do not want to do this. Acquiring a wakelock interferes with the power management of the system and might surprise your users.