• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Pass J2ME (1) – MIDP State

servlet/jsp 搞代码 7年前 (2018-06-18) 156次浏览 已收录 0个评论

对于Midlet状态,有一个叫application management software的会专门负责管理。你所有要关心的,就是怎样和这个AM打交道。

pauseApp()
destroyApp()
startApp()

http://www.gaodaima.com/41942.htmlPass J2ME (1) – MIDP State

重写这三个方法。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&gt;
* @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);
}
}

欢迎大家阅读《Pass J2ME (1) – MIDP State》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Pass J2ME (1) – MIDP State

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址