Pass J2ME (1) - MIDP State
2008-02-23 10:07:58来源:互联网 阅读 ()
pauseApp()
destroyApp()
startApp()
重写这三个方法。AM将会在相应的时间调用。
而
notifyDestroyed()
notifyPaused()
resumeRequest()
则是让你有机会去通知AM需要做什么。
下面是一个简单的例子,可以根据自己扩充测试一下。有一点比较奇怪的就是,理论上说,在Midlet处于Active状态的时候,如果有电话进入,AM会调用pauseApp()。但是实际测试时,没有发现AM调用这个方法。
package net.csdn.blog.vincint;
import Javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* This is a simple test to help me understanding the Midlet state
*
* <p>Title: Midlet Test</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: http://blog.csdn.net/Vincint</p>
* @author Vincint
* @version 1.0
*/
public class MidletState
extends MIDlet
implements
CommandListener {
protected Form form;
protected Command exitCmd;
protected Command debugCmd;
protected Display display;
protected String debug;
public MidletState() {
addDebugInfo("In MidletState()");
display = Display.getDisplay(this);
form = new Form("Hello world.");
form.append("What a new world!");
exitCmd = new Command("Exit", Command.EXIT, 1);
debugCmd = new Command("Debug", Command.SCREEN, 2);
form.addCommand(exitCmd);
form.addCommand(debugCmd);
form.setCommandListener(this);
}
/**
* startApp
*/
protected void startApp() {
addDebugInfo("In startApp()");
display.setCurrent(form);
}
/**
* pauseApp
*/
protected void pauseApp() {
addDebugInfo("In pauseApp()");
}
/**
* destroyApp
*
* @param boolean0 boolean
*/
protected void destroyApp(boolean boolean0) {
addDebugInfo("In destroyApp(" boolean0 ")");
}
/**
* commandAction
*
* @param command Command
* @param displayable Displayable
*/
public void commandAction(Command command, Displayable displayable) {
addDebugInfo("In commandAction(...)");
if (command == exitCmd) {
destroyApp(true);
notifyDestroyed();
}
else if (command == debugCmd) {
notifyUser(debug, form);
}
}
protected String addDebugInfo(String debugMsg) {
if (debug == null) {
debug = new String();
}
debug = debug.concat(debugMsg "\n");
return debugMsg;
}
protected void notifyUser(String message, Displayable screen) {
Alert alert = new Alert("Info", message, null, AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, screen);
}
}
上一篇: 使用java将csv文件分割
下一篇: Spring Framework 1.1.5 has just been released
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash