You can control the device screen saver with the Nokia UI API. By default, the screen saver starts automatically if the device user does not press any key within a certain timeframe. You can prevent this by keeping the screen backlight active with the Nokia UI API. The Nokia UI API provides DeviceControl.setLights method for controlling the screen backlight.
Forcing the display to be constantly switched on consumes more battery. To take this into account, program the MIDlet to disable the screen saver only when on the foreground, for example.
The DeviceControl.setLights method activates and deactivates the screen backlight on the device. When used to activate the backlight, the method switches the backlight on and resets the user inactivity timers on the device. If called in a loop, the backlight activation prevents the screen saver from starting.
Using the DeviceControl.setLights method to prevent the screen saver from starting is supported since Series 40 1st Edition.
Using the DeviceControl.setLights method overrides the device's ambient light sensor settings and can thus change the screen brightness.
Resetting the user inactivity timers also prevents the automatic keypad lock from being activated.
The following example shows how to use the DeviceControl.setLights method to prevent the screen saver from starting. The screen saver timeout value is configurable, but it cannot be accessed using Java, so a hard-coded value is used in the example loop.
class DisableScreenSaver extends Thread { public void run() { while(true) { DeviceControl.setLights(0, 100); try { Thread.sleep(4000); // minimum screen saver timeout in UI is 5 seconds } catch (InterruptedException e) { } } } } public class MyMidlet extends MIDlet { public void startApp() { new DisableScreenSaver().start(); ... } ... }