Note that there are some explanatory texts on larger screens.

plurals
  1. POPersistent Store in Java Given Runtime Store
    primarykey
    data
    text
    <p>I am trying to create a persistent and shared variable that will keep track of the number of notifications available to the user in a Blackberry app. This number is showed on the home screen and should be kept even after the device is turned off until they check the application themselves, then the number is reset. I have been using a singleton to share the variable between the background process and the UI app itself below:</p> <pre><code>import net.rim.device.api.system.RuntimeStore; public class IconManager { private static IconManager _instance; private static final long GUID = 0xab4dd61c5d004c18L; private int iconCount; // constructor private IconManager() { iconCount = 0; } public static IconManager getInstance() { if (_instance == null) { _instance = (IconManager) RuntimeStore.getRuntimeStore().get(GUID); if (_instance == null) { IconManager singleton = new IconManager(); RuntimeStore.getRuntimeStore().put(GUID, singleton); _instance = singleton; } } return _instance; } public int getCount() { return iconCount; } public void setCount(int count) { iconCount = count; } } </code></pre> <p>I have been mainly using this site to try to figure out the Persistent store portion: <a href="http://supportforums.blackberry.com/t5/Java-Development/Storing-persistent-data/ta-p/442747" rel="nofollow">http://supportforums.blackberry.com/t5/Java-Development/Storing-persistent-data/ta-p/442747</a></p> <p>Is there an alternative to implement the persistent store given the above runtimestore? I was originally thinking of using code from the Blackberry example, but I'm confused on how to do this. From another thread user <em>mparizeau</em> wrote the following:</p> <pre><code>persistentCount = PersistentStore.getPersistentObject(0xdec6a67096f833cL); synchronized (persistentCount) { if (persistentCount.getContents() == null) { persistentCount.setContents(new StoreInfo()); persistentCount.commit(); } } _data = (StoreInfo)persistentCount.getContents(); </code></pre> <p>Now when you want to update it and save to the PersistentStore you can have something like:</p> <pre><code>_data.incElement(); synchronized(persistentCount) { persistentCount.setContents(_data); persistentCount.commit(); } </code></pre> <p>Could this be used in the above code somehow? I am extremely new to java and BB development so any help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload