简体   繁体   中英

Android Development: How can I keep screen on when the activity of my app is at background?

I have tried the following code:

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

However, it only works when the program is on screen.

My app will launch Chrome to visit a website and it becomes background. At this time, it doesn't work.

If I want to keep the screen on when I launch my app, even though it may be at background, how can I do to implement it?

Try to create a class that extends service then add

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

It will run on background even your app is not on screen. You can also use wakelock. You can see a good tutorial here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM