I am using the following codes in my app to keep my device screen from timing out/shutting off. I have used right permissions in my Manifest.
Screen Keep On:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Screen Off:
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Those codes work if the app is running. However, when I close the app the flags seem to clear automatically leaving my device to timeout as normal. I want to keep screen on even if the app is closed. I've tried looking into Wakeful Receiver service but I can't seem to get it to work right. Also, I noticed Wakeful Receiver was depreciated in API 26. Any ideas? Thanks in advance!