Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent automatic screen lock on android by code?

In my app there is a long loading process, and if the devices puts on the screen lock, my process stops for some reason.

How can i prevent the device from automatic screen lock?

like image 523
Adam Varhegyi Avatar asked Jul 05 '12 12:07

Adam Varhegyi


People also ask

How do I disable auto Screen lock on Android?

Turn off auto-lock (Android tablet)Open Settings. Tap the applicable menu option(s), such as Security or Security & location > Security, then locate and tap Screen lock. Select None.

How do I turn off lock screen code?

How to remove Screen Lock on your Android phone. Tap Settings > Security > Screen Lock. If prompted, enter your current lock screen code > None > Delete.


1 Answers

Another way to keep the screen lock on without having to request the permission in the manifiest is:

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

Are you doing your long loading process in the UI thread? Something doesn't seem right - if the process is so long that the screen lock timesout and your process ends, perhaps it needs to go in a background service.

like image 109
barry Avatar answered Sep 22 '22 12:09

barry