This question already has an answer here:
- Force Screen On 3 answers
For my Android app I never want the phone to lock or the back light to turn off
This question already has an answer here:
For my Android app I never want the phone to lock or the back light to turn off
Don't Use Wake Lock.
The easiest way is to use the below code when you want to keep your screen on..
One addition to the answer if you want to remove or terminate keep_Screen_on
you can also see here..
And
the best and easiest way
.. Usingandroid:keepScreenOn="true"
in layout root of your activity does the same thing without extra code. But it will remain it in Keep_Scree_on State..It can be vary on your demand See here
You can simply use
setKeepScreenOn()
from the View class.No need to add permission and do tricks. Just use below text in your main layout.
Use PowerManager.WakeLock class inorder to perform this. See the following code:
Use the follwing permission in manifest file :
Hope this will solve your problem...:)
At this point method
is deprecated.
You should use
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
andgetWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow
is a method defined for activities, and won't require you to find aView
first.