Marty Cochrane
Marty Cochrane

Reputation: 689

Stop android device from sleeping

I'm trying to develop a very simple app that displays like a slideshow of images which Im sure ill be able to figure out (if anyone has any advice would be much appreciated) but what im wondering is there any way I can stop the device from going to sleep if its left cycling through these images?

Upvotes: 1

Views: 2577

Answers (3)

Hazem Farahat
Hazem Farahat

Reputation: 3790

using

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

will make the screen always on which will disable the lock. Remove it by using

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

Upvotes: 6

CommonsWare
CommonsWare

Reputation: 1006554

Add android:keepScreenOn="true" to some widget in your activity's layout XML file. While the activity is in the foreground, the device will not fall asleep.

Upvotes: 4

Related Questions