03-04-2013 04:16 PM
We have a java library project to share common code between all our java-based clients. We have created a "linked src folder" to the library project in our client project in addition to the src folder that belongs to the client project. There is a file in the library that contains "static final" objects that are created when the application runs.
The problem is that though the application starts and the static final objects are created as expected, the first time the client code tries to reference one of these objects all the objects get reinitialized again. We are seeing this only on the BlackBerry. The same approach works fine on J2ME and Android.
Please advise on how we could solve this issue?
Solved! Go to Solution.
03-04-2013 06:19 PM
I suspect the problem here is that static values are not shared between different Application instances - and by Application here I mean different instances of the Application class (UiApplication extends Application).
So, for example, if you have an alternate entry point, and a normal entry point, these two will see different instances of static values. In your case, I suspect the client application and the start-up application are diffrent instances.
If you want to share variables between two different Application instances then the best option is runtimestore:
03-04-2013 08:34 PM
I am using the runtime store and the implementation or initialization of the application singleton is done exactly as in the link you posted.
After debugging it for sometime, I believe I have narrowed down the issue. In our application we like to be notified on the states of a phone call and thus we extended the AbstractPhoneListener. It is only when the first call notification incoming/initiated) is received and a reference to the "static object" made is when all the static objects are reinitialized.
Accessing the "static objects" when the phone app is not active does not trigger the reinitialization. I am suspecting that there is an instance of our application in the phone application because the reinitialization happens only once and only when a phone application comes active. Could this be true? If so, how would I work around this?
03-05-2013 02:46 AM
03-07-2013 08:24 PM
I found a workaround and that is to use invokeLater. If the stattic final constants are called from the run method of a Runnable that is passed to invokeLater the constants are not reinitialized.
However the invokeLater is slow. If I were to switch to using global event as an alternative, how fast would that be considering a phone application process is active and we are dispatching a global event from that context?
03-07-2013 09:12 PM
If all you are trying to do is access shared data, then RuntimeStore is the way to go and fast.
GlobalEvent involves at least one invokeLater (the event is processed on the Event Thread on the target application) so I would not think that it would be faster than invokeLater.
How did you get the application to do the invokeLater against?
03-07-2013 09:35 PM
I am trying to notify another thread in my application about the call states. We notify threads using asynchronous messaging. The static final constants are essentially just the names of those threads
My application is a singleton, I retrieved an instance of it and called invokeLater.
03-08-2013 03:11 AM
03-08-2013 04:28 AM
Just backing up Simon's comments.
You said "My application is a singleton, I retrieved an instance of it and called invokeLater"
I presume therefore that you are using RuntimeStore to provide that Singleton. If you can do that, then you can put anything in there, including the names of the Threads.
Putting your Application in RuntimeStore means that all your Application variables, screens and so on will not be garbage collected when you exit your Application, which might not be a great idea.