静态变量的值保持从previous推出 [英] static variables keep values from previous launch

查看:129
本文介绍了静态变量的值保持从previous推出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的J2ME应用程序调用 destroyApp()方的notifyDestroyed()当它要被关闭
当我在黑莓运行它,在第二次发射的静态变量将他们previous运行有相同的价值观。

My j2me application call destroyApp() and notifyDestroyed() when it wants to be closed when I run it on blackberry, in the second launch the static variables will have the same values they had in previous run.

为什么他们没有得到的初始值?我怎样才能确保应用程序初始化静态变量?

Why they don't get the initial value? How can I make sure the application initialize static variables?

推荐答案

此的黑莓在技术支持论坛表明,这是一个已知的问题与黑莓手机的MIDlet的讨论 - 至少用静推登记的。他们提出的解决方法是在的startApp 或要么重新定义静态变量摆脱静推的。

This discussion at Blackberry support forums suggests that it is a known issue with BlackBerry MIDlets - at least with those using static push registries. Workarounds they suggest are either re-define static variables in startApp or get rid of static push.

这看起来后大量值得引述,因为有一个很好的code为例,分析问题:

This post looks worth extensive quoting, since there is a nice code example and issue analysis:

我能想出的最简单的例子是这样的:

The simplest example I could come up with is this:

public class BasicMIDlet extends MIDlet {

    private static byte myByte = Byte.MIN_VALUE;

    public void startApp() {
        System.out.println("My byte: " + myByte);
        myByte = Byte.MAX_VALUE;
        notifyDestroyed();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }


}

您所期望myByte输出到-128每次应用程序启动时,
  但是这是我的输出:

You would expect myByte to output to -128 every time the app starts, but this is my output:

--------------------------------------------------------

Starting BBTest
Started BBTest(159)
Foreground BBTest(157)
My byte: -128                          <------------
Foreground net_rim_bb_ribbon_app(83)
Exit BBTest(159)
Starting BBTest
Started BBTest(160)
Foreground BBTest(157)
My byte: 127                          <------------
Foreground net_rim_bb_ribbon_app(83)
Exit BBTest(160)
Starting BBTest
Started BBTest(161)
Foreground BBTest(157)
My byte: 127                          <------------
Foreground net_rim_bb_ribbon_app(83)
Exit BBTest(161)
--------------------------------------------------------


  
  

我注意到的东西,如果我删除静推登记时,
  应用可以正常工作,输出每次-128。一个是的,我
  有一个MIDlet上RIMlet之上运行同样的感觉,而在
  MIDlet的定义推登记的情况下,RIMlet正在运行的所有
  时间。所以,我现在的问题是,是否有比其它任何解决方案
  初始化在每次运行静态变量(因为有
  大约> 1000这样的成员在我的应用程序)

I have noticed something, if I remove the static push registries, the application behaves normally and outputs -128 every time. An yes, I have the same feeling that a MIDlet runs on top of a RIMlet, and in the case the midlet defines push registries, the RIMlet is running all the time. So my question now is, are there any solutions other than initializing the static variables on every run (because there are roughly >1000 such members in my app)

这篇关于静态变量的值保持从previous推出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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