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
nilavya
Posts: 22
Registered: ‎04-07-2008
My Device: Not Specified

Re: Static Data

I have only single application which is registerd for listening to Contact Menu Extensions and also the PhoneListener. The need is to perform some specific action on Phone Listner depending on the flag value which is set in my Project. Also there is only one Main function in the entire project. 

 

Regards,

/nd 

Developer
peter_strange
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: Static Data

I agree with marchywka that if you were using this code within a number of Threads, then there is no need to use RuntimeStore.  However, you say in your original post, that you are using this from a number of packages, so I suspect that you are using this across processes or application instances, in which case I think RuntimeStore is the appropriate way to go.

 

The code you have supplied doesn't look quite right to me, and I think is more complicated than it needs to be too.  I've knocked up something that I think will do the job for you - it is a variation on something that I have that seems to work.  Also you should be able to extend it easily to add other things to your 'global store.  The only issue with this is that I'll beat you are going to want to persist this at some stage - that is a challenge for you!

 

I'm not guaranteeing that this code is 100% correct and any improvements/suggestions are welcome!

 

To use this code, you just need to use GlobalAccess.getFlag() and GlobalAccess.setFlag(...).

 

public class GlobalAccess extends Object { static final long RUNTIMESTOREUID = 0xc8bd3acd66a144e7L; private static GlobalAccess _singletonGlobalAccess; protected boolean _myFLag; public GlobalAccess() { _myFLag = false; } public static boolean setFlag(boolean newFlag) { if ( _singletonGlobalAccess != null ) { synchronized(_singletonGlobalAccess) { _singletonGlobalAccess._myFLag = newFlag; } return true; } return false; } public static boolean getFlag() { if ( _singletonGlobalAccess != null ) { return _singletonGlobalAccess._myFLag; } return false; } static { RuntimeStore rtStore = RuntimeStore.getRuntimeStore(); try { _singletonGlobalAccess = (GlobalAccess) rtStore.get(RUNTIMESTOREUID); if ( _singletonGlobalAccess == null ) { _singletonGlobalAccess = new GlobalAccess(); rtStore.replace(RUNTIMESTOREUID, _singletonGlobalAccess); } _singletonGlobalAccess = (GlobalAccess) rtStore.waitFor(RUNTIMESTOREUID); } catch (Exception e) { _singletonGlobalAccess = null; System.out.println("Exception: " + e.toString()); } } }

 

New Developer
nilavya
Posts: 22
Registered: ‎04-07-2008
My Device: Not Specified

Re: Static Data

Excellent. Really appreciate your help. That solved my problem. Once again appreciate all your help and looking into the issue.

 

Cheeeeers..!!!! :smileyhappy:

Regards,

/nd