Before marking this post as a \"duplicate\", I am writing this post because no other post holds the solution to the problem.
I am trying to turn off the device, then
To keep screen on:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Back to screen default mode: just clear the flag FLAG_KEEP_SCREEN_ON
getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);