Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Trusted Contributor
WorkHorse
Posts: 100
Registered: 01-13-2012
My Carrier: Simulator
Accepted Solution

Does a singleton store persistently?

I need an update count in my application such that the user will know how many notifications they have. 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. 

 

 

Please use plain text.
Developer
simon_hain
Posts: 10,780
Registered: 07-29-2008
My Carrier: O2 Germany

Re: Does a singleton store persistently?

there is a difference between a soft off (hang up key or off button) and a hard off (battery pull). a soft off suspends applications, and they wake up again when the device powers on again.

if you pull the battery (or close the simulator) all non-persistant values are lost.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

peter_strange wrote:
"This process should happen traumatically for you in both JDE and Eclipse."
Please use plain text.
Developer
swap_chau
Posts: 121
Registered: 06-15-2011
My Carrier: Vodaphone

Re: Does a singleton store persistently?

If you want to simulate hard reset you can restart the simulator. Pressing End button will only soft reset it.

Please use plain text.
Trusted Contributor
WorkHorse
Posts: 100
Registered: 01-13-2012
My Carrier: Simulator

Re: Does a singleton store persistently?

Would this be simply closing the simulator window and selecting the project and Run As -> simulator again?

Please use plain text.
Developer
simon_hain
Posts: 10,780
Registered: 07-29-2008
My Carrier: O2 Germany

Re: Does a singleton store persistently?

yes
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.

peter_strange wrote:
"This process should happen traumatically for you in both JDE and Eclipse."
Please use plain text.