Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7490327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:35:00+00:00 2026-05-29T15:35:00+00:00

I currently have code to share a variable between two entry points in my

  • 0

I currently have code to share a variable between two entry points in my application. The variable is the iconCount variable used to indicate how many notices the user has which is displayed on the home screen beside the icon. The way I’ve managed to do this is with a singleton and it (seems) to work fine at the moment. The issue is now that I do not want those notices to reset to zero when I completely turn off and turn on the phone. Should there be 7 notifications, I want there to be 7 notifications even after a device restart. For this I apparently need a persistent store integration which I’ve researched for a while.

So far my code for the bare singleton is:

public class MyAppIndicator{
    public ApplicationIndicator _indicator; 
    public static MyAppIndicator _instance; 

    MyAppIndicator () {
        setupIndicator();   
    }

    public static MyAppIndicator getInstance() {
        if (_instance == null) {
            _instance = new MyAppIndicator ();
        }
        return(_instance);
    }

    public void setupIndicator() {

        //Setup notification 
        if (_indicator == null) {
            ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
            _indicator = reg.getApplicationIndicator();

            if(_indicator == null) {
                ApplicationIcon icon = new ApplicationIcon(EncodedImage.getEncodedImageResource ("notificationsdemo_jde.png"));
                _indicator = reg.register(icon, false, true);  
                _indicator.setValue(0);
                _indicator.setVisible(false);
            }
        }
    }

    public void setVisible1(boolean visible, int count) {

        if (_indicator != null) {
            if (visible) {
                _indicator.setVisible(true);
                _indicator.setValue(count); //UserInterface.incrementCount()
            } else {
                _indicator.setVisible(false);
            }
        }
    }
}

I have been using the blackberry tutorial to figure out how to implement the persistable storage: http://supportforums.blackberry.com/t5/Java-Development/Storing-persistent-data/ta-p/442747

Now before I go any further I must stress I’m very new to java development so my coding might be completely wrong, but here is what I’ve tried to do:

public void setVisible1(boolean visible, int count) {

    if (_indicator != null) {
        if (visible) {
            _indicator.setVisible(true);
            _indicator.setValue(count); //UserInterface.incrementCount()
            StoreInfo info = new StoreInfo(); 
            info.incElement();

            synchronized (persistentCount) { 
                //persistentCount.setContents(_data); 
                persistentCount.commit(); 
            } 


        } else {
            _indicator.setVisible(false);
        }
    }
}

static { 
    persistentCount = PersistentStore.getPersistentObject(0xdec6a67096f833cL); 
    synchronized (persistentCount) { 
        if (persistentCount.getContents() == null) { 
            persistentCount.setContents(new Vector()); //don't know what to do with this?
            persistentCount.commit(); 
        } 
    } 
} 

private static final class StoreInfo implements Persistable{
    private int iconCount;
    public StoreInfo(){}

    public int getElement(){
        return (int)iconCount;
    }

    public void incElement(){
        iconCount++;             //persistently increment icon variable
    }

    public void resetElement(){
            iconCount=0;             //when user checks application
    }
}   

The code above doesn’t work which I’d expect somehow because I’m having trouble implementing the persistent portion. If anyone has any idea or input on how to accomplish this any assistance would be helpful. And of course thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:35:01+00:00Added an answer on May 29, 2026 at 3:35 pm

    In the example they have a variable called _data that holds the StoreInfo class, so first of all you should be keeping the StoreInfo in some variable. To do this have something like the following in your static initializer:

    persistentCount = PersistentStore.getPersistentObject(0xdec6a67096f833cL); 
    synchronized (persistentCount) { 
        if (persistentCount.getContents() == null) { 
            persistentCount.setContents(new StoreInfo());
            persistentCount.commit(); 
        } 
    }  
    _data = (StoreInfo)persistentCount.getContents();
    

    Now when you want to update it and save to the PersistentStore you can have something like:

    _data.incElement();
    synchronized(persistentCount) {
        persistentCount.setContents(_data);
        persistentCount.commit();
    }
    

    Assuming you’re going to only ever have one instance of StoreInfo it could be better to put the commit code into the modifier methods so you don’t forget to save the new values to the PersistentStore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
I currently have code that does the following: private final static ExecutorService pool =
I currently have code in objective C that can pull out an integer's most
Using dotnet 2.0. I currently have code like this : DataView dv = new
I currently have my code set to disable the submit button when the field
I currently have this code which reads the first field in a database record
I currently have some code which when you press the submit button, a marker
Ok I currently have this code public int i = 0; //this is outside
Hello I currently have this code checking if a cookie exists, it works all
I'm using Zend_Search_Lucene, the PHP port of Java Lucene. I currently have some code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.