热门文章
阿标在线 动力3.62HTML生成3.62网站文件说明
动力3.62整合动网7.0 SP2插
MDAC2.8 下载!
动力3.62版 防止垃圾留言
动力3.6全方位改动方法
让3.62不同频道实现不同风
把3.62首页登陆为横向代码
动易3.6首页随机FLASH修改
362首页和文章频道页图文幻
个性化修改3.6宝典
3.62轻易实现网摘功能
如何正确统计中文字数?
弹出JAVASCRIPT语法错误对
后台使“网站顶部LOGO地址
最新图片文章横向移动的修
html 生成艺术字
3.6 Sp2 Logo和Banner及广
日期值的计算
汉字转拼音
首页“图片更新”图片滚动
简体中文转换为繁体中文的
如何在css中定义链接的下划
Pass J2ME (1) - MIDP State
[ 录入:阿标 | 点击数: | 更新时间:2005-3-2 14:52:00]
对于Midlet状态,有一个叫application management software的会专门负责管理。你所有要关心的,就是怎样和这个AM打交道。
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);
}
}