1

I am trying to create an app that will keep my device wake until I tell it to turn off via code. I can use the follow code in a application...

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

That will work until I tap on the home soft button and then the flags will clear. So, I thought of putting that code in a foreground notification service and broadcast receiver for my action buttons. I can't getWindow in a service or broadcast receiver classes unfortunately. Is there an easy way to get around this?

My goal is to setFlags to keep the screen on from the Activity, and then the service takes over from there so I can close the app, and the keep on screen stays on until the service is turned off.

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Possible duplicate of [Force Screen On](https://stackoverflow.com/questions/2131948/force-screen-on) – cutiko Mar 28 '19 at 13:37
  • Sorry, that doesn't answer my question because it doesn't mention anything about a service that I am wanting to use. –  Mar 28 '19 at 13:42
  • Services dont last forever, to test this start a service with some logs, close the app and then see if there is any log – cutiko Mar 28 '19 at 15:33

0 Answers0