10-22-2008 06:27 PM
I am wrting a program that consists both a GUI side and also a listener in the background on boot. As the application starts, before i figure whether the app was start from the ribbon or not i first load all the data from the PersistentStore. For some reason the data is only accessible in certain places of the app.
Here is the basic structure of my code:
AppData is where I store all the application data in PersistentStoreTable extends Hashtable implements Persistable
public static void main(String args)
loadCodeModule(); //i first load the module so i can use the CodeModuleGroup to get all the properties from the JAD
AppData.loadProperties(_group); //this is used to load all the properties from the jad into the PersistentStore
if(args != null && args.length > 0 && args.endsWith("gui"))
//Entered by selecting the application icon on the ribbon
//Start the GUI
MyApp ma = new MyApp();
* Entered through the alternate application entry point
* Start the listener only if the service is activated or
* disable prompt is false
Here is my background listener which implements PIMListListener:
_bbContactList = (BlackBerryContactList)PIM.getInstance().openPIMLi
System.out.println("Adding the PIM List listener");
System.out.println("In backgroundlistener constructor => " + AppData.getServerUrl(false)+":"+AppData.getTCPPort
//MyMenuItem myMenuItem = new MyMenuItem(0);
enuItem(ApplicationMenuItemRepository.MENUITEM_ADD RESSBOOK_LIST, myMenuItem);
Logger.log(ERROR, "Problem adding listener to the contact list");
//Returns an instance of the running BackgroundListener
public static BackgroundListener waitForSingleton()
//Ensure this is a singleton instance.
//Open RuntimeStore and obtain the reference of BackgroundListener
RuntimeStore store = RuntimeStore.getRuntimeStore();
Object obj = store.get(RTSID_LISTENER_ID);
//If obj is null, there is no current reference to BackgroundListener
//Start a new instance of BackgroundLIstener if one is not running
if(obj == null)
store.put(RTSID_LISTENER_ID, new BackgroundListener());
public void itemAdded(PIMItem item)
System.out.println("In item added => " + AppData.getServerUrl(false)+":"+AppData.getTCPPort
So the System.out print out the right information in the background listener but then in the itemadded everything printed out to be null. This is beyond my wildest guess of why this is so....
10-22-2008 09:12 PM
The itemAdded method is called by a different process and, if I understand the rim sandboxes, this is a different class load
for AppData. You need to talk to your intended AppData class via globalevent or runtimestore.
I guess you could think of the classes as having a loading process appended to the name [ someone from rim
correct me as I have never actually run into this problem ] so you have AppData$123 which hasn't been initialized
instead of AppData$100 which is probably what you meant.
10-23-2008 07:53 AM
The issue I highlighted is here,
IIRC, you didn't post any persistent store code. Did you post the relevant stuff and also IIRC the runtimestore
usage wasn't relevant to the AppData issue.
You may be able to call Thread.getName() or currentApplicationDescriptor() to see who is calling what
but I'm not sure if "current" means current thread or in foreground which would be a material difference.
Anyway, it does appear that different processes get different class loaders and different "class instances."
runtimestore is not persistent but AFAIK it, and persistentstore and global events are options .
10-23-2008 01:21 PM