I am developing a Blackberry Java application and I need an update count in the app such that the user will know how many notifications they have on the phone. The number of notifications show up on the home screen beside the icon. The way I am keeping track of the icon variable “iconCount” between different entry points is through a singleton. I need to have this count be present even after the user turns off their device on and off. So if there are 7 updates available for them 7 will show up until they check the application. It will not reset to 0 when the device is turned off.
As a test to see what would happen if I set the count to 7 and turned off the device through the simulator; I held down the power button until it stated “turning device off, press any key to abort” then the screen went black. I waited a few seconds and pressed the hangup button again and the simulator powered up to show 7 new notifications.
This is a bit strange to me, I though you would need persistent store to accomplish this? Was I turning off the device properly, or does a singleton in fact hold the variable even after the device is shut off?
A static member (as the singleton) will be unique inside a given application. But because BlackBerry Java implementation is so “particular” (to say the least), for each alternate entry point, you’ll have a different “application instance”, so several instances of your singleton will be created.
If you want to share an object at runtime between several applications, you have to publish it in the
RuntimeStore. If you also need persistence, then usePersistentStore, or plain files, or sqlite databases in newer OSes.And now about the simulator: don’t trust the simulator. Once you close your app your variables will vanish. Even if you have a background process, when you turn off the device it won’t exist any more. Test on a real device.
Remember: BlackBerry is not Java. You’ll see many violations of the Java Specification (like for instance, the fact that the
Persistableinterface is not inherited) so get used to it.