Screen saver goes on automatically, if there are no key presses within certain timeframe. This can be prevented by setting the display light using the Nokia UI API.
Calling DeviceControl.setLights
method just resets
device’s inactivity timer but if it’s called in a loop it will prevent screen
saver activation.
Screen saver timeout value is configurable but it can not be accessed from Java side so hard coded value is used in loop.
class DisableScreenSaver extends Thread { public void run() { while(true){ DeviceControl.setLights(0, 100); try { Thread.sleep(4000); // min. screen saver timeout in UI is 5secs } catch (InterruptedException e) { } } } } public class MyMidlet extends MIDlet { public void startApp() { new DisableScreenSaver().start(); … } … }
Note that forcing the display to be constantly turned on consumes more battery. Real life application would for example disable screen saver only while on foreground.