Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to disable the screen saver on Java ME

From Wiki
Jump to: navigation, search
Article Metadata
Created: User:Soku123 (01 Jun 2007)
Last edited: lpvalente (01 Dec 2013)

This article provides a method to prevent the screen saver from kicking off while your application is running.

If your application doesn't have regular activity (ie key presses) after a while the screen saver on a the phone will start automatically. There is no way to "disable" the screen saver programmatically, but you can stop it from activating by simulating user activity - e.g. by turning the phone backlight on.

To make sure that the display light is turned on, the setLights() method should be called before the screen saver is started and this must be done in a loop since the screen saver is not disabled just interrupted.

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class BacklightWorkaround extends MIDlet {
private SimpleCanvas canvas;
* Keeps the backlight on by repeatedly setting

class LightThread extends Thread {
public void run() {
DeviceControl.setLights(0, 100);
try {
} catch (InterruptedException ex) {
private class SimpleCanvas extends Canvas implements CommandListener{
private Command exitCmd;
private MIDlet midlet;
public SimpleCanvas(MIDlet midlet) {
this.midlet = midlet;
exitCmd = new Command("Exit",Command.EXIT, 1);
public void paint(Graphics g) {
g.drawString("Let there be light.", 0, 0, Graphics.LEFT|Graphics.TOP);
public void commandAction(Command command, Displayable displayable) {
if(command == exitCmd){
public void startApp() {
if(canvas == null){
canvas = new SimpleCanvas(this);
new LightThread().start();
public void pauseApp() { }
public void destroyApp(boolean unconditional) { }
This page was last modified on 1 December 2013, at 13:47.
59 page views in the last 30 days.