在j2me中终止应用程序的问题,但这并不意味着退出应用程序 [英] question for terminate app in j2me but it doesnt mean quit from application

查看:44
本文介绍了在j2me中终止应用程序的问题,但这并不意味着退出应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在j2me中有大小写..我想在应用程序在执行代码时终止.这是我的简单代码.

i have case in j2me .. i want terminate when app in process execute code. this is my simple code.

else if (c == cmdStop) {

                //command berhenti
                browser.stop();

            }


 public void stop(){
             // No errors
                  int errorCode = 0;

                 // An error occurred
                    errorCode = -1;

                  // Terminate
                       System.exit(errorCode);

            }

问题是当我尝试终止应用程序时,该应用程序仍然可以正常工作或继续执行,而忽略了system.exit函数.

the problem is when i try to terminate app, the app still worked or continue execute and ignore function system.exit.

仍执行此代码

private void paintParserScreen(Graphics g){

        int w = width;
        int h = fontHeight+2;
        int x = 0;
        int y = height - h;

        int curLoaded = 0;
        int value = 0;
        int iPercent = 0;



        if(maxElementNum!=0){
            curLoaded = wapRender.getCurLoadedTag();
            value = curLoaded * 100 / maxElementNum;
            iPercent = (curLoaded * (w - 2)) / maxElementNum;
        }

        g.setColor(0x808080);
        g.fillRect(x, y, w, h);

        g.setColor(0x0000ff);
        g.fillRect(x + 1, y + 1, iPercent - 2, h - 1);

        g.setColor(0xffffff);
        g.drawString("proses..." + value+"%", 
                width>>1, y + 1, Graphics.TOP|Graphics.HCENTER);
    }

他们说

java.lang.SecurityException: MIDP lifecycle does not support system exit.
    at java.lang.Runtime.exit(+9)
    at java.lang.System.exit(+7)
    at com.gameislive.browser.Browser.stop(+8)
    at Tampilkan.commandAction(+147)
    at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
    at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
    at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
    at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)

请帮助我应对这种情况怎么办?

please help me what should i do for this case?

推荐答案

所获得的安全异常说明了一切.

The security exception you get says it all.

J2ME应用程序的行为不同于J2SE应用程序.

J2ME applications do NOT behave like J2SE applications.

您不会以相同的方式启动它们,也不会以相同的方式终止它们.

You don't start them in the same way and you don't terminate them in the same way.

在您的情况下,您尝试编写的J2ME应用程序称为MIDlet.

In your case, the kind of J2ME application you are trying to write is called a MIDlet.

MIDlet生命周期由运行在Java虚拟机之上的MIDP运行时进行调节,该Java虚拟机仅执行Java字节码并处理系统资源.

A MIDlet lifecycle is regulated by the MIDP runtime that runs on top of a Java Virtual Machine that simply executes Java bytecode and handles system resources.

启动MIDlet时,MIDP运行时将调用MIDlet构造函数及其javax.microedition.midlet.MIDlet.startApp()替代.

When a MIDlet starts, the MIDP runtime calls the MIDlet constructor and its javax.microedition.midlet.MIDlet.startApp() override.

为了终止MIDlet,MIDP运行时调用javax.microedition.midlet.MIDlet.destroyApp()替代.

In order to terminate a MIDlet, the MIDP runtime calls the javax.microedition.midlet.MIDlet.destroyApp() override.

当MIDlet决定可以终止时,它可以调用自己的destroyApp()而不是等待MIDP运行时执行它.

When the MIDlet decides that it can be terminated, it can call its own destroyApp() instead of waiting for the MIDP runtime to do it.

为了告诉MIDP运行时可以安全终止,MIDlet务必调用javax.microedition.midlet.MIDlet.notifyDestroyed(),通常作为destroyApp()

In order to tell the MIDP runtime that it can be safely terminated, a MIDlet MUST call javax.microedition.midlet.MIDlet.notifyDestroyed(), typically as the last method call in destroyApp()

我建议您阅读 MIDP规范以了解所有内容生命周期和运行时问题.

I suggest reading the MIDP specifications in order to understand all the lifecycle and runtime issues.

最新的 JavaME SDK 还包含许多正确构造的MIDlet以供您参考

The latest JavaME SDK also contains many properly constructed MIDlets for your inspiration.

这篇关于在j2me中终止应用程序的问题,但这并不意味着退出应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆