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
Regarding to Android documentation it can be achieve by using following code line:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
I have added this in my onCreate
method and it works fine.
On the link you will find different ways to achieve this and general explanation as well.
Link to the documenation: https://developer.android.com/training/scheduling/wakelock.html