j2me midlet问题的多个实例

发布于 2024-07-25 09:37:58 字数 570 浏览 3 评论 0原文

我有一个在手机上运行的 j2me midlet。 该代码工作正常,但出现的问题是该程序似乎正在运行多个自身实例。 我在应用程序开头的 appStart() 方法中有代码,该代码在应用程序启动时运行两次。 在程序的生命周期中,当文本写入屏幕时,可以看到代码运行了两次。

代码如下所示:

public MyClass()
{
    form = new Form("MyProgram");
    cmdClose = new Command("EXIT", Command.EXIT, 1);

    form.addCommand(cmdClose);
    form.setCommandListener(this);

    display = Display.getDisplay(this);
    display.setCurrent(form);
}

public void startApp()
{
    form.append("App starting\n");
    // Rest of program
}

我不知道为什么代码被调用两次。

我正在 i290 上编码。

I have a j2me midlet running on a cell phone. The code works fine, but the issue that comes up is that the program seems to be running more than one instance of itself. I have code at the beginning of the application inside the appStart() method that runs twice when the application starts. During the lifetime of the program, the code can be seen running twice when text is written to the screen.

The code looks like this:

public MyClass()
{
    form = new Form("MyProgram");
    cmdClose = new Command("EXIT", Command.EXIT, 1);

    form.addCommand(cmdClose);
    form.setCommandListener(this);

    display = Display.getDisplay(this);
    display.setCurrent(form);
}

public void startApp()
{
    form.append("App starting\n");
    // Rest of program
}

I have no idea why the code is being called twice.

I'm coding on the i290.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情场扛把子 2024-08-01 09:37:58

这绝对是一个 JVM 错误。 startApp() 只能在启动时调用一次,并且在调用 pauseApp() 或调用 notifyPaused() 之前不能再次调用你自己。

我建议的是以下代码:

private boolean midletStarted = false;

public void startApp() {
    if (!midletStarted) {
        midletStarted = true;
        //Your code
    }
}

这样您就可以跟踪 midlet 状态更改。 但事实上,最好根本不使用此方法,而使用构造函数。

哦,顺便说一句,我不认为存在多个实例或类似的情况,这只是一个 JVM 错误。

This is definitely a JVM bug. startApp() should be called only once at startup and can't be called again until pauseApp() is called or you call notifyPaused() yourself.

What I suggest is the following code:

private boolean midletStarted = false;

public void startApp() {
    if (!midletStarted) {
        midletStarted = true;
        //Your code
    }
}

This way you can track midlet state changes. But in fact it is better that you don't use this method at all and use constructor instead.

Oh, by the way, I don't think that there are some multiple instances or something like that, this is merely a JVM error.

迷迭香的记忆 2024-08-01 09:37:58

也许您做了一些操作,导致运行时调用 pauseApp(),然后当您将焦点设置到应用程序时,运行时再次调用 startApp()

将日志记录放入 pauseApp() 中,看看会发生什么。

Maybe you did something that made the runtime call pauseApp() and then when you set the focus to the app the runtime called startApp() again.

Put logging in pauseApp() and see what happens.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文