Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

weird behavior with accessing data from the PersistentStore .... PLEASE HELP

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[0].endsWith("gui"))
{
//Entered by selecting the application icon on the ribbon
//Start the GUI
MyApp ma = new MyApp();
ma.enterEventDispatcher();
}
else
{
/**
* Entered through the alternate application entry point
* Start the listener only if the service is activated or
* disable prompt is false
*/
if((AppData.isInitSetup())
{
BackgroundListener.waitForSingleton();
}
else
{
System.exit(0);
}
}
}

 Here is my background listener which implements PIMListListener:

 

 

public BackgroundListener()
{
/**
*
*/
loadLang();

try
{
_bbContactList = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
System.out.println("Adding the PIM List listener");
_bbContactList.addListener(this);

System.out.println("In backgroundlistener constructor => " + AppData.getServerUrl(false)+":"+AppData.getTCPPort()+":"+AppData.getPhoneNumber()+":"+AppData.getDeviceName());

//MyMenuItem myMenuItem = new MyMenuItem(0);
//ApplicationMenuItemRepository.getInstance().addMenuItem(ApplicationMenuItemRepository.MENUITEM_ADDRESSBOOK_LIST, myMenuItem);
}
catch(Exception e)
{
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());
return (BackgroundListener)store.get(RTSID_LISTENER_ID);
}
else
return(BackgroundListener)obj;
}

public void itemAdded(PIMItem item)
{
System.out.println("In item added => " + AppData.getServerUrl(false)+":"+AppData.getTCPPort()+":"+AppData.getPhoneNumber()+":"+AppData.getDeviceName());
}

 

 
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....

 

Please help

 

 

 

 

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: weird behavior with accessing data from the PersistentStore .... PLEASE HELP

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. 

New Developer
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

Re: weird behavior with accessing data from the PersistentStore .... PLEASE HELP

Even if the PersistentStore and all the variables and accessors were static variables and functions? 
New Developer
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

Re: weird behavior with accessing data from the PersistentStore .... PLEASE HELP

another note, it seems like AppData is only accessible in the BackgroundListener constructor but not anywhere else.
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: weird behavior with accessing data from the PersistentStore .... PLEASE HELP

The issue I highlighted is here,

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=6128

 

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 .

 

 

New Developer
Posts: 28
Registered: ‎07-21-2008
My Device: Not Specified

Re: weird behavior with accessing data from the PersistentStore .... PLEASE HELP

thatks marchywka for all your help.  I'll give runtime store a try.  didn't realize that they may be running on different processes.