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

Posts: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

Issue with object instance coming different for singleton class


I have singleton class getting initalised at the start of my app.I have thread class which which listens to send SMS in it and once i get SMS in my thread class ,I am trying to use instance of singleton class and save in it which has vector in it ,but my instance is coming as null for the thread for the first time but for the second time ,it show instance of first instance created during send first time.

For the other thread which receive SMS,instance is same as which as initialised during app launch,What is mistaking i am making which cause this issue.




Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Issue with object instance coming different for singleton class

I am confident you are attempting to use a static reference to your Singleton class.  In BB Java, a static instance is a Singleton within one Application COntext.  So this works if you don't run any code that runs as part of another application.  But you have listeners, and they will normally run in the context of the Application that you are listening too.  So they do NOT see your Application's static instance, they see their own and it will not have been initialised.


Fix using a Singleton in RuntimeStore: