中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Java > 综合文章
Pass J2ME (1) - MIDP State
作者:未知 时间:2005-07-27 22:27 出处:CSDN 责编:chinaitpower
              摘要:Pass J2ME (1) - MIDP State

对于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);
  }
}


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有