Namespaces
Variants
Actions

How to block the screen saver

Jump to: navigation, search
SignpostIcon Asha UI.png
Article Metadata

Article
Created: User:Soku123 (01 Jun 2007)
Last edited: hamishwillee (11 Jan 2012)

If your application doesn't demand constant key presses, after a while the screen saver on a J2ME phone will start automatically.

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 com.nokia.mid.ui.DeviceControl;
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() {
while(true){
 
DeviceControl.setLights(0, 100);
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
 
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);
addCommand(exitCmd);
setCommandListener(this);
}
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){
midlet.notifyDestroyed();
}
}
}
 
public void startApp() {
if(canvas == null){
canvas = new SimpleCanvas(this);
new LightThread().start();
}
 
Display.getDisplay(this).setCurrent(canvas);
}
 
public void pauseApp() { }
 
public void destroyApp(boolean unconditional) { }
}
This page was last modified on 11 January 2012, at 03:25.
167 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved