To avoid draining the battery, an Android device that is left idle quickly falls asleep. The best way to do this is to use the FLAG_KEEP_SCREEN_ON in your. You can keep your screen awake in Android through two ways. I have read this Or by adding the FLAG_KEEP_SCREEN_ON to the activity. I am trying to make the screen to be always on while my test app is in It only works when the app has a window, i.e. when the user can see its.
FLAG_KEEP_SCREEN_ON. added in API level 1. int FLAG_KEEP_SCREEN_ON. Window flag: as long as this window is visible to the user, keep the device's. Try this answer: getWindow().addFlags(WindowManager.LayoutParams. FLAG_KEEP_SCREEN_ON);. getWindow is a method defined for. I think this should do it: getWindow().clearFlags(android.view.WindowManager. LayoutParams.FLAG_KEEP_SCREEN_ON);. See API for. When each fragment is selected from the navigation drawer, for those you want to have the screen kept on do: getActivity().getWindow.